Skip to content

Comments

[release/10.0] PersistedAssemblyBuilder: Fix encoding of custom modifiers. (#123925)#124537

Merged
JulieLeeMSFT merged 3 commits intodotnet:release/10.0from
jkotas:backport-123857
Feb 24, 2026
Merged

[release/10.0] PersistedAssemblyBuilder: Fix encoding of custom modifiers. (#123925)#124537
JulieLeeMSFT merged 3 commits intodotnet:release/10.0from
jkotas:backport-123857

Conversation

@jkotas
Copy link
Member

@jkotas jkotas commented Feb 18, 2026

Backport of #119935, #121128, #123925 to release/10.0

Customer Impact

  • Customer reported
  • Found internally

Unable to emit references to methods and fields with signatures that include modopts and modreqs using PersistedAssemblyBuilder (e.g. method signatures that use C# readonly ref or in).

Regression

  • Yes
  • No

This is a bug in PersistedAssemblyBuilder that shipped in .NET 9. Adoption blocker with no workaround.

Testing

Dedicated tests.

Risk

Medium. The change is a combination of 3 different PRs that fixed different aspects of the bug. The size of the delta makes is a medium risk.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection-emit
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in PersistedAssemblyBuilder where custom modifiers (like InAttribute on in parameters) were not being correctly encoded in method signatures when using types obtained via GetModifiedParameterType(). The issue manifested as a TypeLoadException when loading assemblies with interface implementations that have custom modifiers on parameters.

Changes:

  • Refactored signature encoding to always extract custom modifiers from types when modifier arrays are null
  • Added a test to verify interface overrides with custom modifiers work correctly
  • Improved code clarity with better variable naming and simplified array encoding

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs Core fix: Modified WriteSignatureForType to extract custom modifiers from types when modifier arrays are null; unified signature encoding logic across fields, methods, properties, and parameters; simplified array encoding
src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs Added regression test SaveInterfaceOverrideWithCustomModifier that validates the fix by creating an interface override with in parameter modifiers and verifying the assembly loads without errors
src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveILGeneratorTests.cs Renamed variable nestedParam to sectorParam for better code clarity
src/libraries/System.Reflection.Emit/tests/System.Reflection.Emit.Tests.csproj Ensured project reference to System.Reflection.Emit source project

Copilot AI review requested due to automatic review settings February 18, 2026 07:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

jgh07 and others added 3 commits February 19, 2026 14:49
…119935)

This fixes dotnet#111003. The current implementation is a **work in progress**, only **managed** function pointers with no modopts are supported.

---------

Co-authored-by: Jan Kotas <[email protected]>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

@teo-tsirpanis teo-tsirpanis added this to the 10.0.x milestone Feb 20, 2026
@JulieLeeMSFT JulieLeeMSFT added the Servicing-consider Issue for next servicing release review label Feb 23, 2026
@rbhanda rbhanda modified the milestones: 10.0.x, 10.0.5 Feb 24, 2026
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Feb 24, 2026
@JulieLeeMSFT JulieLeeMSFT merged commit 7f9a3f1 into dotnet:release/10.0 Feb 24, 2026
157 of 161 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants