A non-static class that implements an interface with static abstract members and is used as a type argument gets flagged by CA1812.
Steps To Reproduce
public interface IProgram {
public static abstract Task RunAsync();
}
public static class ProgramHost {
public static async Task RunAsync<TProgram>()
where TProgram : IProgram {
return TProgram.RunAsync();
}
}
// This triggers CA1812.
internal sealed class Program : IProgram {
public static async Task RunAsync() {
}
}
internal static class GeneratedProgram {
private static Task Main() {
return ProgramHost.RunAsync<Program>();
}
}
Expected behavior
Program should not be flagged by CA1812.
Actual behavior
error CA1812: 'Program' is an internal class that is apparen tly never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static ' (Module in Visual Basic).
Analyzer
Diagnostic ID: CA1812:
Avoid uninstantiated internal classes
Analyzer source
SDK: Built-in CA analyzers in .NET 5 SDK or later
Version: SDK 7.0.100-rc.2.22477.23
Describe the bug
A non-static class that implements an interface with static abstract members and is used as a type argument gets flagged by CA1812.
Steps To Reproduce
Expected behavior
Program
should not be flagged by CA1812.Actual behavior
error CA1812: 'Program' is an internal class that is apparen tly never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static ' (Module in Visual Basic).