-
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
Support Type.GetMember
usage analysis properly with IL3050 warning (NAOT)
#94745
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionUsing the Reproduction StepsEnable AOT compatible analysis: type.GetMember("SomeMethod", MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); Expected behaviorAll that should be necessary to appease the analyser is: [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Actual behaviorRegression?No response Known WorkaroundsIgnore the warning. Configuration.NET SDK 8.0.0 Other informationThis was likely just looked over when implementing the analyser. I've only discovered it now since I'm only now adding AOT support.
|
I'd be happy to make a PR to fix this btw - if someone could point me to the code for this analyser, and people are happy for me to do it. |
I think you're confusing GetMethod with GetMember. You're correct that |
@agocke no I'm not, I specified |
We'd need to extend intrinsic handling of this method in the Roslyn analyzer and in ILLinker/NativeAOT compiler. Searching the codebase for
The warning should be suppressible and this might be safe to suppress (unless there's some obscure corner case behavior difference between |
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsDescriptionUsing the Reproduction StepsEnable AOT compatible analysis: void X(Type t)
{
t.GetMember("SomeMethod", MemberTypes.Method, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
} Expected behaviorAll that should be necessary to appease the analyser is: [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Actual behaviorRegression?No response Known WorkaroundsIgnore the warning. Configuration.NET SDK 8.0.0 Other informationThis was likely just overlooked when implementing the analyser. I've only discovered it now since I'm only now adding AOT support.
|
The fix would be here:
The value of the new enum should already be tracked as an integer by dataflow, so I don't think it would need changes to the dataflow itself. Note that this code is shared by all 3 tools (ILLink, ILCompiler, the analyzer). Would need some more logic to figure out the correct member type masks but probably not too difficult. Technically we can do even better and basically map this onto the handling of GetMethod - which has the ability to preserve only a single method, if the name of the method is a constant. But that's maybe a next level optimization on top. I agree with Michal that we should investigate if there are behavioral differences between |
Yup, my mistake, missed the binding flags. It would be cool to support this properly |
I agree with Michal that we should investigate if there are behavioral differences between Both Line 67 in 2e912a3
Line 106 in 2e912a3
The only differences I see up to this point is that |
Description
Using the
Type.GetMember
function gives warnings that are not necessary when AOT analysis is enabled.Reproduction Steps
Enable AOT compatible analysis:
<IsAotCompatible>true</IsAotCompatible>
.Write code like so:
Expected behavior
All that should be necessary to appease the analyser is:
Actual behavior
Instead I get the following:
Regression?
No response
Known Workarounds
Ignore the warning.
Configuration
.NET SDK 8.0.0
VS 17.8.0
Windows 10.0.19045 x64
I don't see why it would be specific to this configuration
Other information
This was likely just overlooked when implementing the analyser. I've only discovered it now since I'm only now adding AOT support.
The text was updated successfully, but these errors were encountered: