dotnet / dotnet/linker

Consider rewording warnings around DAM to not mention reflection access

Open
#2,526 9 comments 0 reactions 0 assignees View on GitHub
area-Linker: Diagnostic
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

With the following program:

```c#
class Program
{
public static void Main()
{
Foo(typeof(Program));
Bar(typeof(Program));
}

public static void Foo([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type type)
=> Console.WriteLine("Foo");

public static void Bar([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
=> Console.WriteLine("Bar");
}
```

... the following linker warnings are emitted (dotnet SDK 6.0.101):

```
/home/roji/projects/test/Program.cs(13,9): Trim analysis warning IL2111: Program.Main(): Method 'Program.Foo(Type)' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method. [/home/roji/projects/test/Test.csproj]
/home/roji/projects/test/Program.cs(13,9): Trim analysis warning IL2111: Program.Main(): Method 'Program.Bar(Type)' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method. [/home/roji/projects/test/Test.csproj]
```

... although there's no reflection involved.

Curiously, when commenting out the call to Bar, both warnings disappear.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.