Skip to content

[Breaking change]: AssemblyBuilder custom modifier ordering #56739

Open

Description

@jkotas

Description

Starting in .NET 12, System.Reflection.Emit.AssemblyBuilder emits required and optional custom modifiers in the same order as PersistedAssemblyBuilder and the order used by other reflection APIs.

This breaking change does not affect code that uses required and optional custom modifiers in the same manner as C# compiler.

Version

.NET 12 Preview 1

Previous behavior

Transient AssemblyBuilder created using AssemblyBuilder.DefineDynamicAssembly emitted optional custom modifiers before required custom modifiers and preserved the order of modifiers within each supplied array.

New behavior

Transient AssemblyBuilder follows the same custom modifier ordering as PersistedAssemblyBuilder:

  • Required custom modifiers are emitted before optional custom modifiers.
  • Modifiers within each array are emitted in reverse array order, consistent with the order returned by GetRequiredCustomModifiers() and GetOptionalCustomModifiers() APIs.

Type of breaking change

  • Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
  • Behavioral change: Existing binaries might behave differently at run time.

Reason for change

The change makes custom modifier emission consistent between AssemblyBuilder, PersistedAssemblyBuilder and other reflection APIs.

Recommended action

If your application uses System.Reflection.Emit with custom modifiers, review code that passes required or optional custom modifier arrays to reflection emit APIs:

  • Do not manually reverse arrays returned by GetRequiredCustomModifiers() or GetOptionalCustomModifiers() before passing them to reflection emit APIs
  • Reverse the order custom modifiers in manually constructed signatures

Feature area

Core .NET libraries

Affected APIs

System.Reflection.Emit APIs that accept required and optional custom modifier arrays

TypeBuilder.DefineField
TypeBuilder.DefineMethod
TypeBuilder.DefineConstructor
TypeBuilder.DefineProperty
ModuleBuilder.DefineGlobalMethod
MethodBuilder.SetSignature
SignatureHelper.AddArgument
SignatureHelper.AddArguments
SignatureHelper.GetPropertySigHelper


Associated WorkItem - 642165

Activity

  1. added
    breaking-change
    on Nov 4, 2026
  2. added
    🗺️ mapQUEST
    on Nov 4, 2026
  3. added
    🗺️ reQUEST
    on Nov 4, 2026
  4. removed
    🗺️ mapQUEST
    on Nov 4, 2026
  5. removed their assignment
    on Nov 4, 2026
  6. added
    📌 seQUESTered
    and removed
    🗺️ reQUEST
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredbreaking-change

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions