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

IDE0079 incorrectly reported when AnalysisLevel is set to latest-all #76560

Open
Forgind opened this issue Dec 24, 2024 · 1 comment
Open

IDE0079 incorrectly reported when AnalysisLevel is set to latest-all #76560

Forgind opened this issue Dec 24, 2024 · 1 comment
Labels
Area-Analyzers Feature - IDE0079 Remove unnecessary suppression untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@Forgind
Copy link
Member

Forgind commented Dec 24, 2024


Issue moved from dotnet/sdk#44993


From @fgimian on Wednesday, November 20, 2024 10:52:32 PM

Describe the bug

IDE0079 Remove unnecessary suppression is reported incorrectly when <AnalysisLevel>latest-all</AnalysisLevel> is used to enable all analysers.

Edit: This also occurs with an .editorconfig and no AnalysisLevel set. Here's the .editorconfig I used to test it.

root = true

[*.cs]
dotnet_diagnostic.CA1031.severity = warning

To Reproduce

ConsoleApp1.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AnalysisLevel>latest-all</AnalysisLevel>
  </PropertyGroup>

</Project>

Program.cs

using System.Diagnostics.CodeAnalysis;

namespace ConsoleApp1
{
    internal static class Program
    {
        internal static void Main()
        {
            Example.MyMethod();
        }
    }

    internal static class Example
    {
        [SuppressMessage(
            "Design",
            "CA1031:Do not catch general exception types",
            Justification = "I want to catch every possibly exception."
        )]
        public static void MyMethod()
        {
            try
            {
                string text = File.ReadAllText("example.txt");
                Console.WriteLine(text);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex}");
            }
        }
    }
}

Exceptions (if any)

The following warning is reported incorrectly.

Severity	Code	Description	Project	File	Line	Suppression State	Details
Message (active)	IDE0079	Remove unnecessary suppression	ConsoleApp1	C:\Users\Fots\source\ConsoleApp1\Program.cs	15		

If you remove the "unnecessary" suppression, CA1031 is reported for the block.

Severity	Code	Description	Project	File	Line	Suppression State	Details
Warning (active)	CA1031	A general exception such as System.Exception or System.SystemException or a disallowed exception type is caught in a catch statement, or a general catch clause is used. General and disallowed exceptions should not be caught.	ConsoleApp1	C:\Users\Fots\source\ConsoleApp1\Program.cs	22		

Further technical details

  • Include the output of dotnet --info
.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.c6f19616
 MSBuild version:   17.12.7+5b8665660

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100\

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version

Microsoft Visual Studio Version 17.12.1

@Forgind
Copy link
Member Author

Forgind commented Dec 24, 2024

Moved this to roslyn, as they own IDE0079, which presumably doesn't properly respect latest-all.

@deepakrathore33 deepakrathore33 added the Feature - IDE0079 Remove unnecessary suppression label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Feature - IDE0079 Remove unnecessary suppression untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants