PersistedAssemblyBuilder: Fix encoding of custom modifiers.#123925
PersistedAssemblyBuilder: Fix encoding of custom modifiers.#123925jkotas merged 15 commits intodotnet:mainfrom
PersistedAssemblyBuilder: Fix encoding of custom modifiers.#123925Conversation
There was a problem hiding this comment.
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
TempDirectorytest infrastructure and reference theSystem.Reflection.Emitproject.
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. |
...raries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs
Outdated
Show resolved
Hide resolved
...raries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs
Outdated
Show resolved
Hide resolved
...raries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs
Outdated
Show resolved
Hide resolved
...raries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs
Outdated
Show resolved
Hide resolved
|
Hmm, Mono is failing. 🤔 |
The logic of `GetTypeParameter` follows the comment above more closely. Also make `TypeSignature` readonly.
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
|
I took a look at the new Mono failure. |
|
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.
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
They are allowed per the amendments to ECMA-335.
PersistedAssemblyBuilder: Include custom modifiers when importing method reference signatures.PersistedAssemblyBuilder: Fix encoding of custom modifiers.
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
…t/SignatureHelper.cs
|
Thanks for fixing this! Is there any chance that the fix could be backported to .NET 9 and 10? ( |
…#123925) Fixes dotnet#123857. --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
|
I can propose .NET 10 backport. |
…#123925) Fixes dotnet#123857. --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
|
We would need to backport multiple fixes from main to make it work. It is not just the change in this PR. |
Fixes #123857.
Added test that passes locally after the fix.