Skip to content

[main] Add design-time analyzer guardrails and shared analyzer test harness - #15163

Merged
LeafShi1 merged 10 commits into
dotnet:mainfrom
KlausLoeffelmann:copilot/analyzer-harness-designer-guardrails-main
Sep 21, 2026
Merged

LeafShi1 merged 10 commits into
dotnet:mainfrom
KlausLoeffelmann:copilot/analyzer-harness-designer-guardrails-main

Conversation

@KlausLoeffelmann

@KlausLoeffelmann KlausLoeffelmann commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

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

Test environment

  • Windows x64.
  • Repository-local .NET runtime 12.0.0-alpha.1.26466.113.
Microsoft Reviewers: Open in CodeFlow

KlausLoeffelmann and others added 10 commits September 20, 2026 22:34
Co-authored-by: Copilot <[email protected]>

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 <[email protected]>
Copilot-Session: eb1e9da9-0223-477e-97cc-2e4844acb3bf
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 <[email protected]>
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 <[email protected]>
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.24166%. Comparing base (dadb02e) to head (9d0fd27).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15163   +/-   ##
=============================================
  Coverage   37.24166%   37.24166%           
=============================================
  Files            246         246           
  Lines           9774        9774           
  Branches        1029        1029           
=============================================
  Hits            3640        3640           
  Misses          5970        5970           
  Partials         164         164           
Flag Coverage Δ
Debug 37.24166% <ø> (ø)
production 39.36526% <ø> (ø)
test 20.64923% <ø> (ø)
unit 39.36526% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LeafShi1
LeafShi1 merged commit 01dc3d1 into dotnet:main Sep 21, 2026
10 checks passed
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 added a commit that referenced this pull request Sep 21, 2026
…5143)

## Description

Backport the selected .NET 11 Visual Styles fixes to release/11.0 for
RC2.

This PR consolidates the following previously reviewed fixes into a
single backport:

- #14853 - Fix editable control border color in NET11 visual styles
- #14904 - Fix modern RadioButton glyph clipping in RTL layouts
- #14910 - Fix GroupBox background image rendering in .NET 11 visual
styles
- #14865 - Fix CheckBox and RadioButton explicit BackColor handling in
VisualStylesMode.Net11
- #14860 - Fix Button focus indicator when hosted on a TabPage
- #14827 - Fix ComboBox rendering with DropDownStyle.Simple
- #15019 - Fix setting VisualStylesMode to Classic in the Properties
window
- #14887 - Fix text clipping in controls such as TextBox and ComboBox
- #14929 - Fix inherited ForeColor/BackColor updates for controls inside
GroupBox
- #14815 - Fix ToggleSwitch text overlap in RTL layouts
- #15033 - Disable NET11 VisualStylesMode for composite controls until
their layout modernization is completed
- #15113 - Reinstate per\-state Net11 editable\-control border strokes
- #15159 - Fix CheckBox and RadioButton render transparently over a
parent GroupBox BackgroundImage in VisualStylesMode.Net11
- #15163 - Add design-time analyzer guardrails and shared analyzer test
harness

## Customer Impact

- Without these fixes, applications using the .NET 11 Visual Styles may
encounter rendering, layout, color, RTL, and design\-time issues across
several WinForms controls, including TextBox, ComboBox, Button,
CheckBox, RadioButton, GroupBox, and ToggleSwitch.
The changes also prevent NET11 VisualStylesMode from being applied to
composite controls that are not yet ready for the new visual style
behavior.
- The design-time analyzer guardrails detect unsupported
Designer-generated code patterns that can break designer loading or
serialization, and provide actionable guidance without changing
application runtime behavior. Individual diagnostics remain
configurable.

## Regression

Most of the changes in this backport address regressions or incorrect
behavior identified during .NET 11 Visual Styles development and
validation.

#15113 introduces the updated per-state border styling for editable
controls as part of the .NET 11 Visual Styles. The remaining changes fix
rendering, layout, color, RTL, and design-time issues related to the new
visual styles.

#15163 does not address a shipped runtime regression. It introduces
design-time analyzer guardrails and includes fixes for analyzer false
positives, missed cases, and VB analyzer exceptions identified during
development.

The individual changes have been reviewed and validated in their
original PRs, and the selected changes were also tested before this
backport.

## Testing

Each fix includes its corresponding tests and validation from the
original PR.

The selected fixes were also tested together to validate the combined
RC2 changes before backporting them to release/11.0.

### Risk

**Medium.** - The primary risk is in WinForms control rendering and
layout under the .NET 11 Visual Styles, along with the newly added
design\-time analyzer behavior. This backport includes both visual-style
fixes and an intentional visual behavior change for editable\-control
borders introduced by #15113.

The affected areas include:

- Editable control border rendering and state-specific border styling.
- CheckBox and RadioButton colors, glyphs, and background rendering.
- RTL layout for RadioButton and ToggleSwitch.
- GroupBox background, color inheritance, and child-control rendering.
- Button focus indicator rendering.
- ComboBox layout and rendering.
- Text layout and clipping in editable controls.
- VisualStylesMode behavior at design time.
- VisualStylesMode availability for composite controls.
- Design-time analyzer diagnostics. Some diagnostics are enabled as
errors by default and can fail builds containing unsupported
Designer-generated code. The diagnostics remain individually
configurable.

The individual changes have been reviewed and validated in their
original PRs, and the combined changes were tested together before this
backport.


## Fix

Backport the selected .NET 11 Visual Styles changes for RC2, including:

- Introduce the new per-state border styling for editable controls.
- Fix editable-control border colors and text rendering.
- Fix CheckBox, RadioButton, and ToggleSwitch rendering, including RTL
scenarios.
- Fix GroupBox background rendering and inherited colors.
- Fix Button focus indicator rendering.
- Fix ComboBox layout and rendering.
- Fix VisualStylesMode configuration in the Properties window.
- Disable NET11 VisualStylesMode for composite controls that are not yet
ready for the new visual styles.
- Adds design-time analyzer guardrails and the shared analyzer test
infrastructure
@LeafShi1 LeafShi1 added this to the 11.0-rc2 milestone Sep 22, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants