assembly level UnconditionalSuppressMessage is suppressing all warnings in the assembly, even if Scope and Target are set
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
`dotnet publish -r win-x64 -p:PublishTrimmed=true` the following app both with the assembly level suppress attribute, and without:
```C#
using System;
using System.Diagnostics.CodeAnalysis;
[assembly: UnconditionalSuppressMessage("ReflectionAnalysis", "IL2091:UnrecognizedReflectionPattern",
Target = "M:ConsoleApp19.Program.<>c__1",
Scope = "member",
Justification = "Workaround for https://github.com/mono/linker/issues/1416. Outer method has been annotated with DynamicallyAccessedMembers.")]
namespace ConsoleApp19
{
interface IFoo<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TFoo> { }
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
public static void Suppressed<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TOptions>()
{
Configure(a => { Console.WriteLine("This should be suppressed"); });
}
public static void Unsuppressed<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TOptions>()
{
Configure(a => { Console.WriteLine("This should not be suppressed"); });
}
public static void Configure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] TFoo>(Action> a) => a(null);
}
}
```
When I publish without the UnconditionalSuppressMessage, I get 4 warnings (2 for each call to `Configure`):
```
ILLink : Trim analysis warning IL2091: System.Action`1> ConsoleApp19.Program/<>c__1`1::<>9__1_0: 'TFoo' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in 'ConsoleApp19.IFoo'. The generic parameter 'TOptions' of 'ConsoleApp19.Program.<>c__1' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\Users\eerhardt\source\repos\ConsoleApp19\ConsoleApp19\ConsoleApp19.csproj]
C:\Users\eerhardt\source\repos\ConsoleApp19\ConsoleApp19\Program.cs(22,38): Trim analysis warning IL2091: ConsoleApp19.Program.<>c__1.b__1_0(IFooc__1.TOptions>): 'TFoo' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in 'ConsoleApp19.IFoo'. The generic parameter 'TOptions' of 'ConsoleApp19.Program.<>c__1' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\Users\eerhardt\source\repos\ConsoleApp19\ConsoleApp19\ConsoleApp19.csproj]
ILLink : Trim analysis warning IL2091: System.Action`1> ConsoleApp19.Program/<>c__2`1::<>9__2_0: 'TFoo' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in 'ConsoleApp19.IFoo'. The generic parameter 'TOptions' of 'ConsoleApp19.Program.<>c__2' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\Users\eerhardt\source\repos\ConsoleApp19\ConsoleApp19\ConsoleApp19.csproj]
C:\Users\eerhardt\source\repos\ConsoleApp19\ConsoleApp19\Program.cs(27,38): Trim analysis warning IL2091: ConsoleApp19.Program.<>c__2.b__2_0(IFooc__2.TOptions>): 'TFoo' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in 'ConsoleApp19.IFoo'. The generic parameter 'TOptions' of 'ConsoleApp19.Program.<>c__2' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\Users\eerhardt\source\repos\ConsoleApp19\ConsoleApp19\ConsoleApp19.csproj]
```
However, when I publish with the assembly level suppression attribute, which should only be suppressing 1 of those warnings, all 4 of them disappear, and I don't get any warnings.
Since I am only targeting 1 of the 4 warnings, I should still see 3 warnings.
Side-note: It doesn't appear to matter what I put in for `Scope`. I put `Scope = "eric"` and the linker happily kept suppressing all 4 warnings just fine.
cc @mateoatr @sbomer @vitek-karas
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.