-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Enable setting the TypeMap entrypoint assembly via a RuntimeHostConfigurationOption #121513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
entrypoint assembly for building the typemap.
|
Tagging subscribers to this area: @dotnet/illink |
There was a problem hiding this 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 implements a new feature that enables the TypeMap entrypoint assembly to be configured via a RuntimeHostConfigurationOption, allowing TypeMap to be used with Library output types instead of only executable output types. The change provides a way to specify which assembly should be scanned for TypeMap attributes when the entry point assembly is not appropriate (e.g., in library scenarios).
Key changes:
- Added support for
System.Runtime.InteropServices.TypeMappingEntryAssemblyconfiguration option across the CoreCLR compiler, trimmer, and runtime - Modified the
--featureflag in illink to accept string values in addition to boolean values - Added new tests to validate TypeMap entry assembly configuration works correctly
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/TypeMapLazyDictionary.cs | Modified runtime to check AppContext for TypeMappingEntryAssembly override before falling back to entry assembly |
| src/coreclr/tools/aot/ILCompiler/Program.cs | Added runtime knob parsing to extract TypeMappingEntryAssembly and use it for TypeMap metadata |
| src/tools/illink/src/linker/Linker/Driver.cs | Modified --feature flag to accept and store string values alongside boolean values |
| src/tools/illink/src/linker/Linker/LinkContext.cs | Added Features dictionary to store string-valued features |
| src/tools/illink/src/linker/Linker.Steps/MarkStep.cs | Added logic to check Features for TypeMappingEntryAssembly override |
| src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.cs | Added comment explaining test behavior with entry assembly |
| src/tests/Interop/TypeMap/*.cs | Added new runtime test files validating TypeMappingEntryAssembly configuration |
| src/tools/illink/test/Mono.Linker.Tests.Cases/Reflection/*.cs | Added trimmer test cases and updated existing tests for renamed method |
| RuntimeAssembly? startingAssembly; | ||
| if (AppContext.GetData("System.Runtime.InteropServices.TypeMappingEntryAssembly") is string entryAssemblyName) | ||
| { | ||
| startingAssembly = Assembly.Load(entryAssemblyName) as RuntimeAssembly; |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assembly.Load can throw exceptions (e.g., FileNotFoundException, BadImageFormatException) if the assembly name is invalid or not found. Consider wrapping this in a try-catch block and providing a clear error message that includes the assembly name that failed to load, or let the exception propagate with additional context.
| startingAssembly = Assembly.Load(entryAssemblyName) as RuntimeAssembly; | |
| try | |
| { | |
| startingAssembly = Assembly.Load(entryAssemblyName) as RuntimeAssembly; | |
| } | |
| catch (Exception ex) when ( | |
| ex is FileNotFoundException || | |
| ex is FileLoadException || | |
| ex is BadImageFormatException) | |
| { | |
| throw new InvalidOperationException( | |
| $"Failed to load assembly '{entryAssemblyName}' specified by 'System.Runtime.InteropServices.TypeMappingEntryAssembly'.", | |
| ex); | |
| } |
| if (Context.Features.TryGetValue("System.Runtime.InteropServices.TypeMappingEntryAssembly", out string? assemblyNameString)) | ||
| { | ||
| var assemblyName = AssemblyNameReference.Parse(assemblyNameString); | ||
| startingAssembly = Context.TryResolve(assemblyName); |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Context.TryResolve returns null (assembly not found), the code falls back to the entry point assembly without logging or warning. Consider adding a warning message when the specified TypeMappingEntryAssembly cannot be resolved, as this could indicate a configuration error that should be surfaced to users.
| startingAssembly = Context.TryResolve(assemblyName); | |
| startingAssembly = Context.TryResolve(assemblyName); | |
| if (startingAssembly is null) | |
| { | |
| Context.LogWarning( | |
| $"Could not resolve assembly '{assemblyNameString}' specified by the 'System.Runtime.InteropServices.TypeMappingEntryAssembly' feature. Falling back to the entry point assembly.", | |
| origin: null); | |
| } |
| <ItemGroup> | ||
| <RuntimeHostConfigurationOption Include="System.Runtime.InteropServices.TypeMappingEntryAssembly" | ||
| Value="$(TypeMapEntryAssembly)" | ||
| Condition="'$(TypeMapEntryAssembly)' != ''" |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks if TypeMapEntryAssembly is not empty, but line 6 always sets it to 'TypeMapLib5', making this condition always true. Consider removing the condition or explaining why it's needed for cases where the property might not be set.
| Condition="'$(TypeMapEntryAssembly)' != ''" |
Implements the alternative to #121138 mentioned in #121138 (comment)
Enables the TypeMap to be used in Library output types. Projects can set the following RuntimeHostConfigurationOption to enable this behavior. If it exists, this option takes priority over the entrypoint assembly.