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.

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.
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.

Calling Assembly.GetFile only produces `IL3001`. It doesn't produce `IL3002`.
@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.

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.

3 participants