dotnet / dotnet/roslyn

Suppression via preprocessor directive is considered unnecessary for some diagnostics

Open
#78,073 4 comments 1 reaction 0 assignees View on GitHub
Area-IDE
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Full issue information + repro project**:
https://github.com/just-ero/roslyn-issues-repros/tree/main/5.0.0/000_CustomDiagnosticSuppression

### Version

**Roslyn**: 5.0.0-1.25204.1 (ad1c386d)

### Steps to Reproduce

1. Add the following code wherever syntactically applicable:
```cs
#pragma warning disable SYSLIB1054

class C
{
[DllImport("_")]
static extern void M();
}
```
2. Target .NET 7.0 or higher.

### Expected Behavior

The suppression of `SYSLIB1054` is not considered unnecessary.

### Actual Behavior

It is.

---

![`SYSLIB1054` emitted](https://github.com/user-attachments/assets/c5f9eb60-8919-4ff8-a7f9-6838bd391333) ![Suppression marked as unnecessary](https://github.com/user-attachments/assets/c88b3a1f-7d9f-4fa3-b968-6774b75154d3)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.