Add design-time analyzer guardrails and shared analyzer test harness - #15148
Merged
KlausLoeffelmann merged 10 commits intoSep 21, 2026
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 26dc31c8-2e46-4366-8c26-e3c6d2dacc34
Fix analyzer false positives and VB handling, add receiver-aware WithEvents and Handles diagnostics, and improve semantic scope, reference selection, and analysis performance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: eb1e9da9-0223-477e-97cc-2e4844acb3bf
KlausLoeffelmann
requested review from
LeafShi1 and
Olina-Zhang
and
a balanced review from Copilot
September 21, 2026 00:15
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
WFO2013 misses several allocation paths, and VB guidance incorrectly rewrites MyClass receivers as Me.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds shared analyzer testing infrastructure and new C#/VB design-time diagnostics for Designer compatibility and property allocation behavior.
Changes:
- Adds WFO2002–WFO2015 analyzers, descriptors, guidance, and localization.
- Introduces a shared cross-language analyzer test harness.
- Hardens Designer type detection and SDK reference-pack resolution.
| File | Description |
|---|---|
docs/analyzers/WinFormsCSharpAnalyzers.Help.md |
Documents C# diagnostics. |
docs/analyzers/WinFormsVisualBasicAnalyzers.Help.md |
Documents VB diagnostics. |
src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/CSharp/Analyzers/Designer/DesignerFileStructureAnalyzer.cs |
Adds C# structure checks. |
src/System.Windows.Forms.Analyzers.CSharp/src/System/Windows/Forms/CSharp/Analyzers/Designer/InitializeComponentAnalyzer.cs |
Adds C# initialization checks. |
src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Analyzers/Designer/DesignerAnalyzerTests.cs |
Tests C# guardrails. |
src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Analyzers/AvoidPassingTaskWithoutCancellationToken/AvoidPassingTaskWithoutCancellationTokenTest.cs |
Migrates tests to shared harness. |
src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Analyzers/MissingPropertySerializationConfiguration/ControlPropertySerializationDiagnosticAnalyzerTest.cs |
Migrates analyzer/code-fix tests. |
src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/Analyzers/WFO1001/ImplementITypedDataObjectTests.cs |
Migrates WFO1001 tests. |
src/System.Windows.Forms.Analyzers.VisualBasic/src/Analyzers/Designer/DesignerEventAnalyzer.vb |
Adds VB event-model checks. |
src/System.Windows.Forms.Analyzers.VisualBasic/src/Analyzers/Designer/DesignerFileStructureAnalyzer.vb |
Adds VB structure checks. |
src/System.Windows.Forms.Analyzers.VisualBasic/src/Analyzers/Designer/InitializeComponentAnalyzer.vb |
Adds VB initialization checks. |
src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/Analyzers/Designer/DesignerEventAnalyzerTests.vb |
Tests VB event diagnostics. |
src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/Analyzers/Designer/DesignerAnalyzerTests.vb |
Tests VB guardrails. |
src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/Analyzers/AvoidPassingTaskWithoutCancellationTokenTests.vb |
Migrates tests to shared harness. |
src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/Analyzers/MissingPropertySerializationConfigurationAnalyzerTest.vb |
Migrates analyzer/code-fix tests. |
src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/Analyzers/WFO1001/ImplementITypedDataObjectTests.vb |
Migrates WFO1001 tests. |
src/System.Windows.Forms.Analyzers/src/AnalyzerReleases.Unshipped.md |
Registers new diagnostics. |
src/System.Windows.Forms.Analyzers/src/Resources/SR.resx |
Adds diagnostic resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.cs.xlf |
Synchronizes Czech resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.de.xlf |
Synchronizes German resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.es.xlf |
Synchronizes Spanish resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.fr.xlf |
Synchronizes French resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.it.xlf |
Synchronizes Italian resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.ja.xlf |
Synchronizes Japanese resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.ko.xlf |
Synchronizes Korean resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.pl.xlf |
Synchronizes Polish resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.pt-BR.xlf |
Synchronizes Portuguese resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.ru.xlf |
Synchronizes Russian resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.tr.xlf |
Synchronizes Turkish resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.zh-Hans.xlf |
Synchronizes Simplified Chinese resources. |
src/System.Windows.Forms.Analyzers/src/Resources/xlf/SR.zh-Hant.xlf |
Synchronizes Traditional Chinese resources. |
src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Designer/DesignerTypeFacts.cs |
Adds semantic Designer detection. |
src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/DiagnosticCategories.cs |
Adds Designer category. |
src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/DiagnosticIDs.cs |
Defines new rule IDs. |
src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/Diagnostics/SharedDiagnosticDescriptors.cs |
Defines shared descriptors. |
src/System.Windows.Forms.Analyzers/src/System/Windows/Forms/Analyzers/PropertyAllocatesNewInstanceAnalyzer.cs |
Implements WFO2013. |
src/System.Windows.Forms.Analyzers/tests/README.md |
Documents analyzer workflow. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/AnalyzerTestCase.cs |
Defines shared test inputs. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/AnalyzerTestFactory.cs |
Creates language-specific tests. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/Analyzers/AppManifestAnalyzer/AppManifestAnalyzerTests.cs |
Migrates manifest tests. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/CurrentReferences.cs |
Resolves exact SDK reference packs. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/CurrentReferencesTests.cs |
Tests reference resolution. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/DesignerTypeFactsTests.cs |
Tests Designer type detection. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/DiagnosticGuidanceTests.cs |
Tests rendered guidance. |
src/System.Windows.Forms.Analyzers/tests/UnitTests/PropertyAllocatesNewInstanceAnalyzerTests.cs |
Tests WFO2013 behavior. |
src/test/integration/WinformsControlsTest/UserControls/UserControlWithObjectCollectionEditor.cs |
Suppresses intentional WFO2013 behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve MyClass in VB Handles guidance and detect directly returned arrays and anonymous objects in WFO2013. Add cross-language regression coverage and update analyzer help. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move Designer diagnostics into the WFO3000 range, start the usage range at WFO2000, update selected default severities, and clarify release notes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
LeafShi1
added a commit
that referenced
this pull request
Sep 21, 2026
…arness (#15163) ## Proposed changes - Add a shared C#/VB analyzer test harness and migrate existing analyzer and code-fix tests to it. - Add WFO3000-WFO3012 design-time guardrails for generated partial structure, unrolled `InitializeComponent` code, CodeDOM-incompatible constructs, and VB event wiring. - Add WFO2000 as a general usage warning for property getters that directly return newly constructed reference instances. - Detect designer types and member ownership semantically, including `System.ComponentModel.Component` descendants while excluding namespace lookalikes, inherited/external fields, and ordinary user-code references. - Make WFO3000, WFO3001, WFO3003, WFO3004, WFO3006-WFO3008, and WFO3010-WFO3012 errors by default; retain warnings for WFO3002, WFO3005, WFO3009, and WFO2000. - Include concise, language-appropriate repair guidance and synchronize help, release tracking, and localization resources. This is the `main`-targeted replay of #15148. The feature commits were rebased automatically rather than cherry-picked individually. ## Customer impact - Catch generated-code mistakes that break designer loading or serialization, even when the code would run correctly. - Give developers and coding agents actionable mitigation guidance without changing application runtime behavior. - Keep each diagnostic independently configurable. ## Regression? No shipped runtime regression is addressed. This introduces analyzer guardrails and fixes false positives, missed cases, and VB analyzer exceptions found while developing them. ## Risk Medium: the selected enabled-by-default errors can fail builds containing unsupported Designer-generated code. Detection is limited to matching designer partials and framework symbols, except the explicitly general WFO2000 usage rule. No automatic code fixes are offered for transformations that could alter ownership, event wiring, disposal, or threading behavior. ## Test methodology - Rebased all 10 commits from #15148 onto `origin/main` at `dadb02ecc` with no conflicts. - `git range-diff` reports all 10 replayed commits as patch-equivalent. - All 516 analyzer tests pass: shared 73, C# 385, Visual Basic 58. ## Test environment - Windows x64. - Repository-local .NET runtime `12.0.0-alpha.1.26466.113`. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15163)
LeafShi1
approved these changes
Sep 21, 2026
LeafShi1
added a commit
to LeafShi1/winforms
that referenced
this pull request
Sep 21, 2026
…arness (dotnet#15163) ## Proposed changes - Add a shared C#/VB analyzer test harness and migrate existing analyzer and code-fix tests to it. - Add WFO3000-WFO3012 design-time guardrails for generated partial structure, unrolled `InitializeComponent` code, CodeDOM-incompatible constructs, and VB event wiring. - Add WFO2000 as a general usage warning for property getters that directly return newly constructed reference instances. - Detect designer types and member ownership semantically, including `System.ComponentModel.Component` descendants while excluding namespace lookalikes, inherited/external fields, and ordinary user-code references. - Make WFO3000, WFO3001, WFO3003, WFO3004, WFO3006-WFO3008, and WFO3010-WFO3012 errors by default; retain warnings for WFO3002, WFO3005, WFO3009, and WFO2000. - Include concise, language-appropriate repair guidance and synchronize help, release tracking, and localization resources. This is the `main`-targeted replay of dotnet#15148. The feature commits were rebased automatically rather than cherry-picked individually. ## Customer impact - Catch generated-code mistakes that break designer loading or serialization, even when the code would run correctly. - Give developers and coding agents actionable mitigation guidance without changing application runtime behavior. - Keep each diagnostic independently configurable. ## Regression? No shipped runtime regression is addressed. This introduces analyzer guardrails and fixes false positives, missed cases, and VB analyzer exceptions found while developing them. ## Risk Medium: the selected enabled-by-default errors can fail builds containing unsupported Designer-generated code. Detection is limited to matching designer partials and framework symbols, except the explicitly general WFO2000 usage rule. No automatic code fixes are offered for transformations that could alter ownership, event wiring, disposal, or threading behavior. ## Test methodology - Rebased all 10 commits from dotnet#15148 onto `origin/main` at `dadb02ecc` with no conflicts. - `git range-diff` reports all 10 replayed commits as patch-equivalent. - All 516 analyzer tests pass: shared 73, C# 385, Visual Basic 58. ## Test environment - Windows x64. - Repository-local .NET runtime `12.0.0-alpha.1.26466.113`. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/15163)
KlausLoeffelmann
merged commit Sep 21, 2026
eddb061
into
dotnet:integration/11.0-RC2
8 checks passed
KlausLoeffelmann
deleted the
copilot/analyzer-harness-designer-guardrails
branch
September 21, 2026 16:39
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.


Proposed changes
InitializeComponentcode, generated partial structure, and constructs that cannot round-trip through the Designer's CodeDOM contract.System.ComponentModel.Componentdescendants while excluding unrelated namespace lookalikes, inherited/external fields, and ordinary user-code references.WithEventsand receiver-awareHandlesevent wiring, preserving supportedGenerateMember=Falselocal-variable hookups.Customer Impact
Regression?
No shipped runtime regression is addressed. This introduces new analyzer guardrails and fixes false positives, missed cases, and VB analyzer exceptions found while developing them.
Risk
Medium: new enabled-by-default warnings can affect projects that treat warnings as errors. Detection is limited to matching designer partials and framework symbols, except the explicitly general WFO2013 rule. Existing diagnostic IDs and runtime control behavior are preserved.
Additional parser-dependent syntax restrictions remain deferred rather than being enforced speculatively. Modern designer-host round-tripping has not been exercised end to end.
Test methodology
.\build.cmdsucceeded with zero warnings and errors.WithEvents, field ownership, component namespace identity, event receiver distinctions, allocation semantics, and rendered guidance.integration/11.0-RC2;git range-diffconfirms all seven are patch-equivalent, with no conflicts or unrelatedmainhistory.Test environment
integration/11.0-RC2at41736a5e1.Microsoft Reviewers: Open in CodeFlow