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

Conflict between CA1515 and CA1064 for Exception types #7191

Open
jamesgurung opened this issue Feb 13, 2024 · 0 comments · May be fixed by #7234
Open

Conflict between CA1515 and CA1064 for Exception types #7191

jamesgurung opened this issue Feb 13, 2024 · 0 comments · May be fixed by #7234

Comments

@jamesgurung
Copy link

Analyzers

  • CA1515: Consider making public types internal
  • CA1064: Exceptions should be public

Analyzer source

Version: SDK 9.0.100-preview.1

Describe the bug

Setting the visibility of an Exception class to public causes a CA1515 warning, whereas setting it to internal causes a CA1064 warning.

Steps To Reproduce

ConsoleApp1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <AnalysisMode>AllEnabledByDefault</AnalysisMode>
  </PropertyGroup>
</Project>

Program.cs

throw new ExampleException("Test");

public sealed class ExampleException : Exception // or internal
{
  public ExampleException(string message) : base(message) { }
  public ExampleException(string message, Exception innerException) : base(message, innerException) { }
}

Expected behavior

One of the visibility modifiers (public or internal) should compile without either compiler warning.

Actual behavior

Both options result in a compiler warning.

@CollinAlpert CollinAlpert linked a pull request Mar 7, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant