Skip to content

Enable setting the TypeMap entrypoint assembly via a RuntimeHostConfigurationOption - #121513

Merged
jtschuster merged 14 commits into
dotnet:mainfrom
jtschuster:TypeMapAppContext
Dec 15, 2025
Merged

Enable setting the TypeMap entrypoint assembly via a RuntimeHostConfigurationOption#121513
jtschuster merged 14 commits into
dotnet:mainfrom
jtschuster:TypeMapAppContext

Conversation

@jtschuster

Copy link
Copy Markdown
Member

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.

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Runtime.InteropServices.TypeMappingEntryAssembly"
Value="$(TypeMapEntryAssembly)"
Condition="$(TypeMapEntryAssembly) != ''" />
</ItemGroup>

@github-actionsgithub-actionsBot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Nov 10, 2025
@dotnet-policy-servicedotnet-policy-serviceBot added the linkable-framework Issues associated with delivering a linker friendly framework label Nov 10, 2025
@jtschuster
jtschuster marked this pull request as ready for review November 12, 2025 17:51
CopilotAI review requested due to automatic review settings November 12, 2025 17:51

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.TypeMappingEntryAssembly configuration option across the CoreCLR compiler, trimmer, and runtime
  • Modified the --feature flag 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
FileDescription
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/TypeMapLazyDictionary.csModified runtime to check AppContext for TypeMappingEntryAssembly override before falling back to entry assembly
src/coreclr/tools/aot/ILCompiler/Program.csAdded runtime knob parsing to extract TypeMappingEntryAssembly and use it for TypeMap metadata
src/tools/illink/src/linker/Linker/Driver.csModified --feature flag to accept and store string values alongside boolean values
src/tools/illink/src/linker/Linker/LinkContext.csAdded Features dictionary to store string-valued features
src/tools/illink/src/linker/Linker.Steps/MarkStep.csAdded logic to check Features for TypeMappingEntryAssembly override
src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.csAdded comment explaining test behavior with entry assembly
src/tests/Interop/TypeMap/*.csAdded new runtime test files validating TypeMappingEntryAssembly configuration
src/tools/illink/test/Mono.Linker.Tests.Cases/Reflection/*.csAdded trimmer test cases and updated existing tests for renamed method

Comment threadsrc/coreclr/tools/aot/ILCompiler/Program.cs Outdated
Comment threadsrc/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Comment threadsrc/tests/Interop/TypeMap/TypeMapEntryAssemblyApp.csproj Outdated
Comment threadsrc/coreclr/tools/aot/ILCompiler/Program.cs Outdated
However, it's still necessary to set the RuntimeConfigurationOption for
runtime behavior on CoreCLR.

@MichalStrehovskyMichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good otherwise!

Comment threadsrc/tools/illink/src/linker/Linker/LinkContext.cs Outdated
Comment threadsrc/tools/illink/src/linker/Linker/Driver.cs Outdated
Comment threadsrc/tests/Interop/TypeMap/TypeMapEntryAssemblyApp.cs Outdated
@jtschuster
jtschuster merged commit d162bba into dotnet:mainDec 15, 2025
153 of 157 checks passed
RuntimeAssembly? startingAssembly;
if (AppContext.GetData("System.Runtime.InteropServices.TypeMappingEntryAssembly") is string entryAssemblyName)
{
startingAssembly = Assembly.Load(entryAssemblyName) as RuntimeAssembly;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is odd. The as operator implies the returned type could be a non RuntimeAssembly. I don't believe that is true. This is a confusing cast. It should just be (RuntimeAssembly).

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Ah, I forgot (RuntimeAssembly)null! returns null instead of throwing. Will update to make that clear.

simonrozsival added a commit to dotnet/android that referenced this pull request Jan 28, 2026
…ound
- Enable --typemap-entry-assembly flag in ILLink.targets for TypeMap support
- Add workaround in TypeMapAttributeTypeMap for runtimes without dotnet/runtime#121513
- Use AppContext.GetData to get TypeMappingEntryAssembly and set executing assembly
- Add IAndroidCallableWrapper interface for ACW types with GetFunctionPointer
- Update poc-vs-spec.md with ILLink integration details
- Requires locally built ILLink from dotnet/runtime with #121513 support
simonrozsival added a commit to dotnet/android that referenced this pull request Jan 28, 2026
- Remove TrimMode='copy' to allow ILLink to trim unused proxy types
- ILLink uses the 3-arg TypeMapAttribute to determine which proxies to keep
- TypeMaps assembly reduced from 3.6 MB to 33 KB for HelloWorld (99.1% reduction)
- Requires ILLink with --typemap-entry-assembly support (dotnet/runtime#121513)
simonrozsival added a commit to dotnet/android that referenced this pull request Jan 29, 2026
…ound
- Enable --typemap-entry-assembly flag in ILLink.targets for TypeMap support
- Add workaround in TypeMapAttributeTypeMap for runtimes without dotnet/runtime#121513
- Use AppContext.GetData to get TypeMappingEntryAssembly and set executing assembly
- Add IAndroidCallableWrapper interface for ACW types with GetFunctionPointer
- Update poc-vs-spec.md with ILLink integration details
- Requires locally built ILLink from dotnet/runtime with #121513 support
simonrozsival added a commit to dotnet/android that referenced this pull request Jan 29, 2026
- Remove TrimMode='copy' to allow ILLink to trim unused proxy types
- ILLink uses the 3-arg TypeMapAttribute to determine which proxies to keep
- TypeMaps assembly reduced from 3.6 MB to 33 KB for HelloWorld (99.1% reduction)
- Requires ILLink with --typemap-entry-assembly support (dotnet/runtime#121513)
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Feb 5, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzerslinkable-frameworkIssues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jtschuster@MichalStrehovsky@AaronRobinsonMSFT