Add DiagnosticSuppressor (VSMEF013) for IDE0044 on MEF [Import]/[ImportMany] fields#706
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Add DiagnosticSuppressor for IDE0044 on fields with [Import]/[ImportMany] attribute
Add DiagnosticSuppressor (VSMEF013) for IDE0044 on MEF [Import]/[ImportMany] fields
Apr 30, 2026
drewnoakes
approved these changes
Apr 30, 2026
5012451 to
b61a75a
Compare
… (VSMEF013) Agent-Logs-Url: https://github.com/microsoft/vs-mef/sessions/b402f5d5-b5d4-4b6c-95b1-63536ce67b1a Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
b61a75a to
a766645
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
src/Microsoft.VisualStudio.Composition.Analyzers/README.md:20
- The suppressor is documented as applying to MEF
[Import]/[ImportMany]in general, but the implementation only checks MEF v1 (System.ComponentModel.Composition) for field imports. Please clarify this description (e.g., explicitly call out MEF v1) to avoid implying the suppressor applies toSystem.Compositionas well.
## Diagnostic Suppressors
Suppressor ID | Suppressed Diagnostic | Description
--|--|--
VSMEF013 | IDE0044 | Suppresses "Make field readonly" for fields decorated with MEF `[Import]` or `[ImportMany]` attributes, since such fields are assigned at runtime via reflection.
RyanToth3
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IDE0044 ("Make field readonly") fires false positives on fields injected by MEF at runtime via reflection. This adds a
DiagnosticSuppressor— the Roslyn-recommended cross-package suppression mechanism — to silence IDE0044 on such fields.Changes
IDE0044ImportFieldSuppressor.cs— newDiagnosticSuppressor(ID:VSMEF013) that suppresses IDE0044 for fields bearing any[Import]or[ImportMany]attribute from the MEFv1 namespace. Walks the syntax tree from the diagnostic location to resolve the field symbol, then delegates attribute detection to a newUtils.IsImportFieldAttribute()(which handles only MEFv1 and derived custom attributes, since only MEFv1 supports importing fields).Strings.resx— addsVSMEF013_Justificationsuppression justification string.IDE0044ImportFieldSuppressorTests.cs— several test cases using a test-localFakeIDE0044Analyzerto produce IDE0044 in-process. Covers: MEF v1[Import], MEF v1[ImportMany], non-MEF fields (no suppression), and readonly fields.CSharpMultiAnalyzerVerifier+Test.cs— suppressor added to the multi-analyzer test harness.README.md— documents the new suppressor in a "Diagnostic Suppressors" table.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
31bvsblobprodwus2143.vsblob.vsassets.io/opt/hostedtoolcache/dotnet/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/5707D9CCD3909344C2384588AB311A3D/missingpackages_workingdir --packages /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)b53vsblobprodwus2154.vsblob.vsassets.io/opt/hostedtoolcache/dotnet/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/5707D9CCD3909344C2384588AB311A3D/missingpackages_workingdir --packages /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)h8evsblobprodwus2120.vsblob.vsassets.io/opt/hostedtoolcache/dotnet/dotnet /opt/hostedtoolcache/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/vs-mef/vs-mef/bin/Tests/Microsoft.VisualStudio.Composition.Analyzers.Tests/Release/net8.0/Microsoft.VisualStudio.Composition.Analyzers.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/vs-mef/vs-mef/bin/Tests/Microsoft.VisualStudio.Composition.Analyzers.Tests/Release/net8.0/Microsoft.VisualStudio.Composition.Analyzers.Tests.deps.json /home/REDACTED/work/vs-mef/vs-mef/bin/Tests/Microsoft.VisualStudio.Composition.Analyzers.Tests/Release/net8.0/testhost.dll --port 46053 --endpoint 127.0.0.1:046053 --role client --parentprocessid 6219 --telemetryoptedin false(dns block)s8nvsblobprodwus2158.vsblob.vsassets.io/opt/hostedtoolcache/dotnet/dotnet dotnet build src/Microsoft.VisualStudio.Composition.Analyzers/Microsoft.VisualStudio.Composition.Analyzers.csproj -c Release(dns block)/opt/hostedtoolcache/dotnet/dotnet dotnet build test/Microsoft.VisualStudio.Composition.Analyzers.Tests/Microsoft.VisualStudio.Composition.Analyzers.Tests.csproj -c Release(dns block)/opt/hostedtoolcache/dotnet/dotnet dotnet test test/Microsoft.VisualStudio.Composition.Analyzers.Tests/Microsoft.VisualStudio.Composition.Analyzers.Tests.csproj --no-build -c Release -- --filter-class IDE0044ImportFieldSuppressorTests(dns block)xofvsblobprodwus2114.vsblob.vsassets.io/opt/hostedtoolcache/dotnet/dotnet dotnet restore --no-dependencies /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/5707D9CCD3909344C2384588AB311A3D/missingpackages_workingdir --packages /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /tmp/codeql-scratch-9960d47625b9bdfe/dbs/csharp/working/nugetconfig/nuget.config --force(dns block)If you need me to access, download, or install something from one of these locations, you can either: