dotnet / dotnet/roslyn

IDE0076 False Positive

Open
#75,608 0 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

**Version Used**: Visual Studio `17.11.5`

**Steps to Reproduce**:

1. Create a .NET MAUI Hybrid project
2. In an `editorconfig`, set IDE1006 severity to `warning` (ex: `dotnet_diagnostic.IDE1006.severity = warning`)
3. In the `editorconfig` create a naming rule that requires namespaces to be pascal case
```
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_symbols.namespace_group.applicable_kinds = namespace
dotnet_naming_rule.namespaces_should_be_pascal_case.symbols = namespace_group
dotnet_naming_rule.namespaces_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.namespaces_should_be_pascal_case.severity = warning
```
4. Build the project and observe the new warning in `MyProject/Platforms/iOS/Program.cs` because the namespace is not pascal case.
![namespace warning](https://github.com/user-attachments/assets/92165a95-bf89-4291-8ef0-befe5af07ab2)
5. Create a `GlobalSupressions.cs` file and add this suppression
```c#
[assembly: SuppressMessage(
"Style",
"IDE1006:Naming Styles",
Justification = "This namespace will follow the iOS naming standards which starts with a lowercase letter.",
Scope = "namespaceanddescendants",
Target = "~N:MyProject.App.Platforms.iOS"
)]
```
6. Observe the `IDE0076` warning that appears regarding this suppression even though the namespace is valid.
![Image](https://github.com/user-attachments/assets/608534c6-96f3-4706-adbc-b5b2d5e0bbc0)

**Additional Observations**:

- Even though the global suppression produces a `IDE0076` warning, the `IDE006` warning does get properly suppressed as desired.
- If I wrap the suppression with `#pragma warning disable IDE0076`, I then get the warning `IDE0079: Remove unnecessary suppression` regarding the newly added pragma disable which contradicts the initial warning.

**Diagnostic Id**: `IDE0076: Invalid global 'SuppressMessageAttribute'`

**Expected Behavior**:

The `IDE0076` warning should not appear regarding the valid suppression

**Actual Behavior**:

The `IDE0076` warning does appear regarding the suppression

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the .NET MAUI Hybrid scenario with the editorconfig naming rule and the GlobalSupressions.cs declaration shown in the issue. Investigate the IDE0076 analysis for the namespaceanddescendants target, then verify that IDE1006 remains suppressed without producing IDE0076 or requiring a contradictory IDE0079 suppression.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.