dotnet / dotnet/sdk

Seemingly spurious IDE0051 'private member not used' warnings reported in 10.0.200 SDK which were not reported by 10.0.104

Open
#53,378 2 comments 13 reactions 0 assignees View on GitHub
Area-Microsoft.CodeAnalysis.NetAnalyzers untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
When compiling a large project with SDK 10.0.200, it reports a number of IDE0051 warnings which were not flagged by the 10.0.104 SDK. These appear to be false positives. This caused our project to break because it we treat that warning as an error.

### To Reproduce

https://github.com/edyoung/ide0051_test contains a minimal repro. https://github.com/edyoung/ide0051_test/blob/fcbb93050bd4d7c84f2641bf15cf40ec70ef8e44/Extension.cs#L9 is the line producing the error.

When compiled with the 10.0.200 SDK, it reports

```
[main] C:\onebranch\ide0051_test> dotnet build
Restore complete (0.8s)
ide0051_weirdness net10.0 failed with 1 error(s) (0.5s)
C:\onebranch\ide0051_test\Extension.cs(9,27): error IDE0051: Private member 'ExceptionExtensions.Foo' is unused (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0051)
```

When compiled with the earlier SDK, no error is reported. The member Foo is being called so the diagnostic is incorrect.

### Further technical details
details of dotnet --info


.NET SDK:
Version: 10.0.200
Commit: 40cd698e5c
Workload version: 10.0.200-manifests.1520644a
MSBuild version: 18.3.0-release-26119-122+40cd698e5

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

.NET workloads installed:
[maccatalyst]
Installation Source: VS 17.14.37027.9, VS 18.3.11527.330
Manifest Version: 26.2.10191/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maccatalyst\26.2.10191\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 17.14.37027.9, VS 18.3.11527.330
Manifest Version: 10.0.30/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maui\10.0.30\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 17.14.37027.9, VS 18.3.11527.330
Manifest Version: 26.2.10191/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.ios\26.2.10191\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.14.37027.9, VS 18.3.11527.330
Manifest Version: 36.1.2/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.android\36.1.2\WorkloadManifest.json
Install Type: Msi

Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.4
Architecture: x64
Commit: 80d3e14f5e

.NET SDKs installed:
8.0.419 [C:\Program Files\dotnet\sdk]
9.0.312 [C:\Program Files\dotnet\sdk]
10.0.104 [C:\Program Files\dotnet\sdk]
10.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.4 [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:
C:\onebranch\ide0051_test\global.json

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
N/A, the issue reproduces without any IDE

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the minimal repro at edyoung/ide0051_test, especially Extension.cs line 9, and run dotnet build with SDK 10.0.200 and 10.0.104 to compare IDE0051 behavior. Done means the member call is recognized correctly and the spurious warning is no longer emitted while the reported reproduction remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.