A public delegate is defined within an internal class. CA1859 is generated for the delegate.
Steps To Reproduce
Create an executable project, e.g. a console project.
Create a internal class with a public delegate
internal class Class1
{
public delegate void SomeDelegate();
}
Expected behavior
No errors reported
Actual behavior
Error reported:
Class1.cs(3,26): error CA1515: Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)
This false positive seems to happen for any public nested type of an otherwise internal type. The analyzer SHOULD be checking if the target type is "effectively public" rather than marked public.
Analyzer
Diagnostic ID: CA1515:
Consider making public types internal
Analyzer source
SDK: Built-in CA analyzers in .NET 9 SDK or later
Version: SDK 9.0.100-rc.2.24474.11
OR
NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers
Version: 9.0.0-preview.24454.1
Describe the bug
A
public delegate
is defined within aninternal class
. CA1859 is generated for the delegate.Steps To Reproduce
Expected behavior
No errors reported
Actual behavior
Error reported:
Class1.cs(3,26): error CA1515: Because an application's API isn't typically referenced from outside the assembly, types can be made internal (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1515)
Additional context