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

False positive IL2026 on MakeGenericType/Method when there are no annotations/constraints #2480

Closed
roji opened this issue Jan 5, 2022 · 3 comments

Comments

@roji
Copy link
Member

roji commented Jan 5, 2022

When using MakeGenericType/MakeGenericMethod, IL2026 is understandably generated since some generic type parameters may be annotated with DynamicallyAccessedMemberAttribute, but that can't be taken into account by the linker when the type/method isn't known at compile-time.

However, when the type/method is known at compile-time, it seems like the linker could verify whether annotations exist on generic type parameters, and not emit the warning if not:

_ = typeof(Foo<>).MakeGenericType(typeof(string));

class Foo<T>
{
}

From other issues in this repo, it seems that improved support for MakeGenericType/MakeGenericMethod is maybe already in the works - feel free to close this issue if this is already planned etc.

@marek-safar
Copy link
Contributor

/cc @vitek-karas

@vitek-karas
Copy link
Member

This is analyzer-only problem. Meaning the warning is only generated by the roslyn analyzer either in IDE or build. It should NOT be generated by the linker when trimming.

#2209 fixes the analyzer to not issue the warning, but that fix didn't make it into the SDK yet. It's in the 6.0.2xx branch in dotnet/linker, so hopefully it should make it to 6.0.200 SDK eventually.

@roji
Copy link
Member Author

roji commented Jan 5, 2022

@vitek-karas I can confirm that setting <EnableTrimAnalyzer>false</EnableTrimAnalyzer> makes this go away, so that corresponds to what you wrote, thanks!

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