Skip to content

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Sep 29, 2025

When calling Assembly.GetFile, you get IL3001 trim warning and not IL3002.

Changing the suppression to the correct warning.

Copy link
Contributor

@Copilot 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

This PR adds a missing suppression for the IL3001 trim warning related to assembly file path access. The existing code already had suppression for IL3002 but was missing IL3001, both of which are triggered by Assembly.GetFile calls.

  • Adds UnconditionalSuppressMessage attribute for IL3001 warning
  • Uses the same justification as the existing IL3002 suppression

@MichalStrehovsky
Copy link
Member

When calling Assembly.GetFile, you get 2 trim warnings - IL3001 and IL3002.

That sounds like a bug to me. IL3001 was a somewhat unsystematic addition and the tool generating the more general IL3002 is likely not special casing for it. It should likely only generate the special IL3001.

@eerhardt
Copy link
Member Author

When calling Assembly.GetFile, you get 2 trim warnings - IL3001 and IL3002.

That sounds like a bug to me. IL3001 was a somewhat unsystematic addition and the tool generating the more general IL3002 is likely not special casing for it. It should likely only generate the special IL3001.

Good call. I tested it in a standalone app:

typeof(Program).Assembly.GetFile("ConsoleApp13.dll");

And it only produces IL3001:

❯ dotnet publish
Restore complete (3.3s)
    info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  ConsoleApp13 succeeded with 2 warning(s) (5.6s) → bin\Release\net10.0\win-x64\publish\
    D:\source\ConsoleApp13\ConsoleApp13\Program.cs(1,1): warning IL3001: 'System.Reflection.Assembly.GetFile(String)' will throw for assemblies embedded in a single-file app
    D:\source\ConsoleApp13\ConsoleApp13\Program.cs(1): warning IL3001: Program.<Main>$(String[]): 'System.Reflection.Assembly.GetFile(String)' will throw for assemblies embedded in a single-file app

I've replaced the suppression with the right number.

@eerhardt
Copy link
Member Author

eerhardt commented Oct 3, 2025

@MichalStrehovsky - it looks like there is a bug here somewhere. The build is now failing with

src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Assemblies/Ecma/EcmaAssembly.ManifestResources.cs(89,28): error IL3002: (NETCORE_ENGINEERING_TELEMETRY=Build) Using member 'System.Reflection.Assembly.GetFile(String)' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. This member throws an exception for assemblies embedded in a single-file app.

So it looks like the trimmer is raising IL3002 for this call.

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky - it looks like there is a bug here somewhere. The build is now failing with

Yeah, that doesn't sound right. This looks like it comes from the Roslyn analyzer that actually invented the IL3001 code. I'm on extended leave of absence right now so I'm not going to look at it this month but someone from @dotnet/illink could help in the meantime.

@sbomer
Copy link
Member

sbomer commented Oct 7, 2025

I think this happens because the analyzer sees a call to the derived GetFile, while ILLink/ILC see a call to the base method in IL. This is tracked by #120475. I think it's safe to suppress for now and we can remove it when that issue is fixed.

When calling Assembly.GetFile, you get 2 trim warnings - IL3001 and IL3002.

This was only suppressing one of these warnings. Adding the suppression for the other with the same justification.

IL3002 is an extraneous suppression due to #120475.
@eerhardt eerhardt force-pushed the eerhardt-suppress-ecmaassembly branch from 6b7fea3 to ca6dc06 Compare October 7, 2025 20:18
@eerhardt
Copy link
Member Author

eerhardt commented Oct 7, 2025

OK. I added both suppressions back to the latest changes. Thanks for the investigation here @sbomer.

@eerhardt
Copy link
Member Author

@sbomer - is this good to merge?

@eerhardt eerhardt merged commit 0022d30 into main Oct 11, 2025
86 checks passed
@akoeplinger akoeplinger deleted the eerhardt-suppress-ecmaassembly branch October 11, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants