Skip to content

Add design-time analyzer guardrails and shared analyzer test harness - #15148

Merged
KlausLoeffelmann merged 10 commits into
dotnet:integration/11.0-RC2from
KlausLoeffelmann:copilot/analyzer-harness-designer-guardrails
Sep 21, 2026
Merged

KlausLoeffelmann merged 10 commits into
dotnet:integration/11.0-RC2from
KlausLoeffelmann:copilot/analyzer-harness-designer-guardrails

Conversation

@KlausLoeffelmann

@KlausLoeffelmann KlausLoeffelmann commented Sep 18, 2026

Copy link
Copy Markdown
Member

Proposed changes

  • Add a shared C#/VB analyzer test harness and migrate existing analyzer/code-fix tests to it.
  • Add WFO2002-WFO2012 design-time guardrails for unrolled InitializeComponent code, generated partial structure, and constructs that cannot round-trip through the Designer's CodeDOM contract.
  • Detect designer types and member ownership semantically, including System.ComponentModel.Component descendants while excluding unrelated namespace lookalikes, inherited/external fields, and ordinary user-code references.
  • Add VB-specific WFO2014/WFO2015 for WithEvents and receiver-aware Handles event wiring, preserving supported GenerateMember=False local-variable hookups.
  • Keep WFO2013 as a separate general property-construction warning, excluding value types and nested-function returns and avoiding claims that every getter access allocates.
  • Include actionable, language-appropriate repair guidance in emitted diagnostics; synchronize help, release tracking, and localization resources.
  • Fix analyzer reference-pack selection and avoid unnecessary semantic/operation analysis outside relevant code.

Customer Impact

  • Catch generated-code mistakes that break designer loading or serialization, even when the code would run correctly.
  • Give developers and coding agents concise mitigation instructions without modernizing historical designer infrastructure or changing application runtime behavior.
  • New diagnostics are configurable warnings and do not offer potentially unsafe automatic rewrites.

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

  • Before rebasing: authoritative .\build.cmd succeeded with zero warnings and errors.
  • Before rebasing: all 498 analyzer tests passed (shared: 61; C#: 385; VB: 52), including regressions for VB optional syntax/casing, WithEvents, field ownership, component namespace identity, event receiver distinctions, allocation semantics, and rendered guidance.
  • Verified all 13 localization files against the diagnostic resources.
  • Replayed only the seven feature commits onto integration/11.0-RC2; git range-diff confirms all seven are patch-equivalent, with no conflicts or unrelated main history.
  • This PR requests Azure Pipelines validation against the integration branch and its SDK configuration. The pre-rebase results are not presented as a post-rebase CI result.

Test environment

  • Windows x64, repository-local .NET SDK for the pre-rebase local runs.
  • PR base: integration/11.0-RC2 at 41736a5e1.
Microsoft Reviewers: Open in CodeFlow

KlausLoeffelmann and others added 7 commits September 18, 2026 09:38
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
KlausLoeffelmann requested a review from a team as a code owner September 18, 2026 16:39
@KlausLoeffelmann
KlausLoeffelmann requested review from LeafShi1 and Olina-Zhang and a balanced review from Copilot September 21, 2026 00:15
@KlausLoeffelmann KlausLoeffelmann added the area-Analyzers/CodeFixes A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed. label Sep 21, 2026
@KlausLoeffelmann KlausLoeffelmann added this to the 11.0-rc2 milestone Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 1 Medium severity

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.

KlausLoeffelmann and others added 3 commits September 20, 2026 17:52
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 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
KlausLoeffelmann merged commit eddb061 into dotnet:integration/11.0-RC2 Sep 21, 2026
8 checks passed
@KlausLoeffelmann
KlausLoeffelmann deleted the copilot/analyzer-harness-designer-guardrails branch September 21, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Analyzers/CodeFixes A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants