-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unnecessary Trim analysis warnings for internal static fields of a RequiresUnreferencedCode class #81864
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsDescriptionIn dotnet/aspnetcore#46518 I am trying to mark some ASP.NET classes as
Reproduction StepsUsing https://github.com/vitek-karas/illinkrepro, I was able to get a repro of this issue. Run illink with the rsp file in the repro.zip. Expected behaviorThere should be no ILLink warnings when running the linker. Actual behaviorThe linker reports 2 warnings for these Regression??? Known WorkaroundsA workaround is to move the static fields to a separate type that isn't annotated with RequiresUnreferencedCode. ConfigurationNo response Other information
|
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsDescriptionIn dotnet/aspnetcore#46518 I am trying to mark some ASP.NET classes as
Reproduction StepsUsing https://github.com/vitek-karas/illinkrepro, I was able to get a repro of this issue. Run illink with the rsp file in the repro.zip. Expected behaviorThere should be no ILLink warnings when running the linker. Actual behaviorThe linker reports 2 warnings for these Regression??? Known WorkaroundsA workaround is to move the static fields to a separate type that isn't annotated with RequiresUnreferencedCode. ConfigurationNo response Other information
|
The command-line arguments include
In my mind this is somewhat expected, since the input is asking to preserve things for unknown reasons, and I think we made some exceptions for similar circumstances where members were referenced via XML, but I don't remember the details. Maybe @vitek-karas does. |
I think warning at the places that use these fields is reasonable, since the class is marked |
I "think" (didn't check the code) that we intentionally suppress RUC when caused by a direct reference from a descriptor XML. But otherwise we report it always. As for this case, the The descriptor case should be similar, but I honestly don't remember why we chose not to warn in that case. My main guess would be: there are cases in corelib and similar where we ran into the warning and there's no good way to suppress it (since it doesn't originates in code). For this specific use case in ASP.NET we have basically two options:
|
The part that I still don't get is why static fields are treated specially here. We aren't warning for all the "visible" methods in the same class with
I agree that this isn't critical to fix right now, especially considering this "library" mode isn't a fully supported feature. I was able to workaround it by moving the fields into a separate static class. dotnet/aspnetcore@a68e4c8 |
* Remove incorrect/unnecessary trimming suppressions. These suppressions weren't not correct. Instead they should be RequiresUnreferencedCode. * Work around dotnet/runtime#81864
That's a great point - and I missed this. We need to look into this some more. Whatever the behavior is (I could explain away both ;-)), it should be consistent. |
…84620) Marking an assembly as "library" will mark all public APIs. If some of the marked members have RUC on them we decided we don't want to produce warnings, since there's nothing especially wrong with the library. The callers of those members would still get the right warnings. Currently linker implements this correctly for methods and properties, but it fails for fields and events and it still produces some warnings, especially if the RUC is on the parent type. This change fixes those cases and adds a special test for the library marked assembly in combination with several RUCs. Fixes #81864
Description
In dotnet/aspnetcore#46518 I am trying to mark some ASP.NET classes as
RequiresUnreferencedCode
. However, in doing that, it is causing the ASP.NET LinkabilityChecker to fail with some unexpected warnings:These fields are only used by other
RequiresUnreferencedCode
code, so I don't expect the trimmer to warn about them.Reproduction Steps
Using https://github.com/vitek-karas/illinkrepro, I was able to get a repro of this issue. Run illink with the rsp file in the repro.zip.
repro.zip
Expected behavior
There should be no ILLink warnings when running the linker.
Actual behavior
The linker reports 2 warnings for these
internal
static fields on a class annotated as RequiresUnreferencedCode.Regression?
??
Known Workarounds
A workaround is to move the static fields to a separate type that isn't annotated with RequiresUnreferencedCode.
Configuration
No response
Other information
cc @sbomer @vitek-karas
The text was updated successfully, but these errors were encountered: