Repository navigation
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🔖 Ready
Activity