Skip to content

Linker should warn when reflection-accessing annotated methods #1764

Closed
@MichalStrehovsky

Description

@MichalStrehovsky

When we have a method that is an intrinsic for flow analysis purposes, or has parameters marked as [DynamicallyAccessedMembers], or is marked [RequiresUnreferencedCode], linker should warn when we see that method being reflection accessed.

The problem this is trying to avoid is someone e.g. locating MakeGenericMethod (that currently warns if used statically) and reflection-invoking it with some parameters. The initial reflection access should be a warning since illink is not capable of figuring out the dataflow into the method. Someone could be violating the annotations, resulting in a broken app without warnings.

See https://github.com/dotnet/runtime/pull/47134/files#diff-e09e7f6880244829d1c3b16e19b451ab04d059a7df0d8a367cd3fd08230c9096R64.

We should probably extend this to delegates pointing to such methods (although that one has a natural extension - we could require the delegate invoke method itself to be annotated same as the target).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions