Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA1515: false positive with classes used as parameter types for public members #7519

Open
AbakumovAlexandr opened this issue Dec 26, 2024 · 0 comments

Comments

@AbakumovAlexandr
Copy link

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.101

OR

NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers

Version: 9.0.0

Describe the bug

A public class which is used as parameter type for a public member in another class gets triggered with CA1515.

Steps To Reproduce

  1. Create a public class:
public class Class1 // <- CA1515
{
}
  1. Create another class which uses Class1 as parameter type for its public member:
public class Class2
{
    public Class2(Class1 class1)
    {
    }
}

Expected behavior

No CA1515 issue reported.

Actual behavior

Issue reported:
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)

If I made Class1 internal instead like CA1515 suggests, I get the following build error:
CS0051: Inconsistent accessibility: parameter type 'Class1' is less accessible than method 'Class2.Class2(Class1)'

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant