Skip to content

Comments

PersistedAssemblyBuilder: Fix encoding of custom modifiers.#123925

Merged
jkotas merged 15 commits intodotnet:mainfrom
teo-tsirpanis:sre-import-custom-mods
Feb 17, 2026
Merged

PersistedAssemblyBuilder: Fix encoding of custom modifiers.#123925
jkotas merged 15 commits intodotnet:mainfrom
teo-tsirpanis:sre-import-custom-mods

Conversation

@teo-tsirpanis
Copy link
Contributor

Fixes #123857.

Added test that passes locally after the fix.

Copilot AI review requested due to automatic review settings February 3, 2026 00:08
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 3, 2026
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

Fixes PersistedAssemblyBuilder emitting incorrect method reference signatures by ensuring required/optional custom modifiers (e.g., modreq(InAttribute) for in parameters) are preserved, preventing TypeLoadException when loading saved assemblies.

Changes:

  • Update signature blob generation to include custom modifiers from reflected parameter/return Types when explicit modifier arrays aren’t provided.
  • Add a regression test covering an interface method override involving a required custom modifier (modreq).
  • Update the test project to include TempDirectory test infrastructure and reference the System.Reflection.Emit project.

Reviewed changes

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

File Description
src/libraries/System.Reflection.Emit/tests/System.Reflection.Emit.Tests.csproj Adds TempDirectory support and a project reference needed for the new test scenario.
src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs Adds regression test that saves/loads an assembly implementing an in-parameter interface method.
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs Ensures method signature encoding includes required/optional custom modifiers from the Type when importing method references.

Copilot AI review requested due to automatic review settings February 4, 2026 02:04
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 3 out of 3 changed files in this pull request and generated no new comments.

@teo-tsirpanis
Copy link
Contributor Author

Hmm, Mono is failing. 🤔

The logic of `GetTypeParameter` follows the comment above more closely.
Also make `TypeSignature` readonly.
Copilot AI review requested due to automatic review settings February 9, 2026 01:26
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 4 out of 4 changed files in this pull request and generated 1 comment.

@teo-tsirpanis
Copy link
Contributor Author

I took a look at the new Mono failure. NestedType.TypeSignature.ParameterIndex contains the index of the method parameter, but here we treat it as the index of the generic parameter?

@jkotas
Copy link
Member

jkotas commented Feb 9, 2026

Sounds like a bug to me.

The `ParameterInfo` object contains the index on its own; we shouldn't pass it to the `TypeSignature`'s `ParameterIndex`, because it gets used as index to generic parameter.
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 6 out of 6 changed files in this pull request and generated no new comments.

@teo-tsirpanis teo-tsirpanis changed the title PersistedAssemblyBuilder: Include custom modifiers when importing method reference signatures. PersistedAssemblyBuilder: Fix encoding of custom modifiers. Feb 17, 2026
Copilot AI review requested due to automatic review settings February 17, 2026 17:10
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 6 out of 6 changed files in this pull request and generated no new comments.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thank you!

@jkotas jkotas merged commit 2ff39b5 into dotnet:main Feb 17, 2026
103 of 107 checks passed
@teo-tsirpanis teo-tsirpanis deleted the sre-import-custom-mods branch February 17, 2026 21:36
@stakx
Copy link
Contributor

stakx commented Feb 17, 2026

Thanks for fixing this! Is there any chance that the fix could be backported to .NET 9 and 10?

(in parameters are so common these days that PersistedAssemblyBuilder isn't very useful IMHO if it doesn't support them.)

jkotas added a commit to jkotas/runtime that referenced this pull request Feb 18, 2026
…#123925)

Fixes dotnet#123857.

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
jkotas pushed a commit to jkotas/runtime that referenced this pull request Feb 18, 2026
@jkotas
Copy link
Member

jkotas commented Feb 18, 2026

I can propose .NET 10 backport.

jkotas pushed a commit to jkotas/runtime that referenced this pull request Feb 18, 2026
jkotas pushed a commit to jkotas/runtime that referenced this pull request Feb 18, 2026
jkotas added a commit to jkotas/runtime that referenced this pull request Feb 19, 2026
…#123925)

Fixes dotnet#123857.

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@jkotas
Copy link
Member

jkotas commented Feb 19, 2026

We would need to backport multiple fixes from main to make it work. It is not just the change in this PR.
#124537

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection.Emit community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PersistedAssemblyBuilder: TypeLoadException with in method parameters

4 participants