dotnet/roslyn
View on GitHubIDE0051 should factor in new dependency attributes in .NET 5
Open
#48,206 opened on Sep 30, 2020
Area-IDEConcept-Continuous ImprovementFeature - IDE0051help wanted
Repository metrics
- Stars
- (20,414 stars)
- PR merge metrics
- (Avg merge 6d 17h) (256 merged PRs in 30d)
Description
Version Used: 3.9.0-1.20480.1+b3c3f4875957e51526000898673291d11708d35b
Steps to Reproduce:
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
class Program
{
static void Main() => new Program().Bar();
[DynamicDependency("Foo")]
private void Bar() => typeof(Program).GetMethod("Foo", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, null);
private void Foo() => Console.WriteLine("Hello");
}
Expected Behavior: .NET 5 adds new attributes that enable dependencies not obvious in the code, e.g. those via reflection, to be used for dead code elimination tools like https://github.com/mono/linker to better understand such dependencies. IDE0051 is such a tool and should ideally respect these attributes, such that in this example, IDE0051 doesn't fire.
Actual Behavior:
IDE0051 fires and suggests deleting the "unused" method:

cc: @eerhardt, @nickcraver