Add CS0649 suppressor for MEF imported fields#737
Merged
Conversation
Add a C#-only suppressor for CS0649 on MEF-imported fields, move compiler-specific suppressors into the CSharp analyzer assembly, add compiler-level tests for C# and VB behavior, and document the new suppressor in the analyzer docs and repo instructions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR extends the VS MEF analyzer package with a new compiler diagnostic suppressor to reduce false-positive warnings for MEF-imported fields that are assigned at composition time, and updates the related test and documentation infrastructure.
Changes:
- Add
VSMEF018to suppressCS0649for MEF imported fields on exported parts. - Move compiler-diagnostic suppressors to the C# analyzer assembly and share import/export detection logic via a new helper utility.
- Add targeted tests (including a VB “no equivalent warning” probe) and update README/DocFX documentation + Copilot instructions.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.VisualStudio.Composition.Analyzers.Tests/Helpers/CSharpMultiAnalyzerVerifier+Test.cs | Registers the new suppressor in the multi-analyzer harness. |
| test/Microsoft.VisualStudio.Composition.Analyzers.Tests/CS0649ImportingMemberSuppressorTests.cs | Adds compiler-level tests validating CS0649 suppression behavior and a VB probe test. |
| src/Microsoft.VisualStudio.Composition.Analyzers/README.md | Documents VSMEF018 in the suppressor catalog table. |
| src/Microsoft.VisualStudio.Composition.Analyzers.CSharp/ImportingMemberSuppressorUtilities.cs | Introduces shared utilities for consistent MEF import/export detection in suppressors. |
| src/Microsoft.VisualStudio.Composition.Analyzers.CSharp/CS8618ImportingMemberSuppressor.cs | Moves/adjusts CS8618 suppressor to be C#-only and to use the shared utilities. |
| src/Microsoft.VisualStudio.Composition.Analyzers.CSharp/CS0649ImportingMemberSuppressor.cs | Adds the new CS0649 suppressor implementation. |
| docfx/analyzers/VSMEF018.md | Adds a DocFX page describing the new suppressor. |
| docfx/analyzers/toc.yml | Adds VSMEF018 to the analyzer docs TOC. |
| docfx/analyzers/index.md | Adds VSMEF018 to the analyzer docs index. |
| .github/copilot-instructions.md | Records analyzer/suppressor documentation update locations for future contributions. |
Narrow the suppressor to IFieldSymbol since CS0649 only applies to fields, keeping the implementation strongly typed and clearer. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
davkean
approved these changes
Jun 19, 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.
Why
MEF assigns imported fields during composition, so valid imported fields can trigger CS0649 even though they are populated at runtime. This change adds the missing suppressor and documents it alongside the existing analyzer catalog.
What changed
VSMEF018to suppressCS0649on imported fields of exported MEF partsCS0649andCS8618suppressors into the C# analyzer assemblydocfx/analyzers/and the analyzer package README.github/copilot-instructions.mdso future analyzer additions update the docs consistentlyNotes for reviewers
The VB probe changed the shape of the implementation a bit: instead of keeping a C#-only suppressor in the shared analyzer assembly with an
RS1004suppression, the compiler-specific suppressors now live in the C# analyzer assembly. A small shared helper in that assembly keeps the import/export detection logic consistent betweenCS0649andCS8618.