-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
NativeAOT's implementation of TrimmerRootAssembly
is too aggressive
#92271
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsFor example: TestApp.csproj (normal console app) <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TestLib\TestLib.csproj" />
<TrimmerRootAssembly Include="TestLib" />
</ItemGroup>
</Project> And then the using System.Runtime.Loader;
namespace TestLib;
internal class Derived : AssemblyLoadContext
{
} Now running (on the TestApp):
The output will contain Now publishing the same app with NativeAOT:
Using sizoscope tells us that In short, the NativeAOT implementation of assembly rooting seems to be rooting too much. For example it seems to fully root all base types of the types from the target assembly, including all members on such base types. This is not a problem necessarily for cases where It would also be nice to make the behavior consistent between
|
For example:
TestApp.csproj (normal console app)
And then the
TestLib
containsNow running (on the TestApp):
The output will contain
AssemblyLoadContext
class in CoreLib, but for example theAssemblyLoadContext.GetAssemblyName
method will be missing from it (since it's not used anywhere).Now publishing the same app with NativeAOT:
Using sizoscope tells us that
AssemblyLoadContext.GetAssemblyName
is actually preserved in the app.In short, the NativeAOT implementation of assembly rooting seems to be rooting too much. For example it seems to fully root all base types of the types from the target assembly, including all members on such base types.
This is not a problem necessarily for cases where
TrimmerRootAssembly
is used as a workaround to trim incompatibilities (it's adds more code), but it can matter more when it's used in a test app to validate trim/AOT compatibility of a library.It would also be nice to make the behavior consistent between
illink
andilc
.The text was updated successfully, but these errors were encountered: