dotnet / dotnet/linker

Analysis hole: attributes on instance methods in RUC types

Open
#3,140 8 comments 0 reactions 1 assignee Claimed by @sbomer View on GitHub
area-Linker: Diagnostic
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

RUC on type silences warnings from instance methods, but those instance methods may have attributes that should produce warnings. We incorrectly treat RUC on type as suppressing those warnings, even though reflection access to those methods can call the attribute ctor at runtime. Example:

```csharp
class RequiresOnAttributeCtorAttribute : Attribute
{
[RUC("--ATTRIBUTE CTOR--")]
public RequiresOnAttributeCtorAttribute()
{
Console.WriteLine("ATTRIBUTE CTOR CALLED!");
}
}

[RequiresUnreferencedCode("--TypeWithRequires--")]
class TypeWithRequires
{
[RequiresOnAttributeCtor]
public void InstanceMethod() { }
}

public static void Test()
{
foreach (var method in typeof(TypeWithRequires).GetMethods(BindingFlags.Public | BindingFlags.Instance))
{
foreach (var a in method.GetCustomAttributes()) ;
}
}
```

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.