Skip to content
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

Supporting both RequiresUnreferencedCode and DynamicallyAccessedMembers annotations on a method #1815

Closed
eerhardt opened this issue Feb 9, 2021 · 2 comments
Assignees
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Feb 9, 2021

In dotnet/runtime#47938, we are annotating a method with both RequiresUnreferencedCode and DynamicallyAccessedMembers attributes. This should do both:

  • Raise an ILLink warning when someone calls it
  • Preserve the necessary members that are dynamically accessed.

See dotnet/runtime#47938 (comment).

The scenario here is that part of a method may be trim compatible (like using Reflection to find a method by name), but another part may be incompatible (like calling MakeGenericMethod if the caller passed in a Type[] typeArguments value).

We should ensure this scenario works as expected.

@vitek-karas
Copy link
Member

The intended behavior is:

  • Callers will get a warning due to the RequiresUnreferencedCode
  • Callers will apply the requirements of the DynamicallyAccessedMembers on the method parameters
  • The method body will not produce data flow warnings
  • The method body is still fully analyzed and if it adds requirements on something that will be applied

#1827 adds a test to validate this - but it already works that way.

@vitek-karas
Copy link
Member

As noted above, the behavior is already as expected and the test coverage has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants