Skip to content

Add AppContext switch to guard automation peer disconnect behavior#11723

Closed
amarinov-msft wants to merge 1 commit into
pr-11657from
amarinov/appcontext-switch-disconnect-peer-v2
Closed

Add AppContext switch to guard automation peer disconnect behavior#11723
amarinov-msft wants to merge 1 commit into
pr-11657from
amarinov/appcontext-switch-disconnect-peer-v2

Conversation

@amarinov-msft

@amarinov-msft amarinov-msft commented Jun 15, 2026

Copy link
Copy Markdown

Fixes #11337

Main PR #11717

Description

Adds an AppContext compatibility switch (Switch.System.Windows.Automation.Peers.UseLegacyAutomationPeerDisconnect) to guard the new UIA disconnect behavior introduced in #11717 .

When false (default): removed automation peers are disconnected via UiaDisconnectProvider, fixing the memory leak where CCW ref counts never drop to zero.

When true: legacy behavior is preserved - removed peers are not disconnected, maintaining the old element lifetime semantics for consumers that depend on it.

Customer Impact

Without this switch, the disconnect fix in #11717 unconditionally changes observable UIA behavior: removed peers get UiaDisconnectProvider'd and their proxy _peer is cleared, so clients still holding cached elements receive ElementNotAvailableException instead of data. Test automation harnesses and AT products that depend on the old element lifetime would break with no escape hatch.

Regression

No

Testing

Risk

Low. The switch is purely additive infrastructure - it defines a new AppContext switch and guards the #11717 call sites behind a property check.

Microsoft Reviewers: Open in CodeFlow

@amarinov-msft amarinov-msft requested a review from a team as a code owner June 15, 2026 12:33
@amarinov-msft amarinov-msft added the PR metadata: Label to tag PRs, to facilitate with triage label Jun 15, 2026
@amarinov-msft amarinov-msft force-pushed the amarinov/appcontext-switch-disconnect-peer-v2 branch from 4659075 to ee49533 Compare June 15, 2026 12:37
Add Switch.System.Windows.Automation.Peers.UseLegacyAutomationPeerDisconnect
to guard the new UIA disconnect behavior behind an opt-out compatibility switch.

When false (default): removed automation peers are disconnected via
UiaDisconnectProvider, fixing the memory leak described in #11337.

When true: legacy behavior is preserved - removed peers are not disconnected,
maintaining the old element lifetime semantics for consumers that depend on it.

The switch follows the existing WPF accessibility switch pattern:
- Defined in AccessibilitySwitches.cs with GetCachedSwitchValue
- Defaulted to false in SetSwitchDefaults (new behavior on by default)
- Wired into VerifyDependencies against UseNetFx472CompatibleAccessibilityFeatures
- Forwarded via CoreAppContextSwitches for use in PresentationCore

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@amarinov-msft

Copy link
Copy Markdown
Author

Closing the PR as this will be addressed in #11657

@amarinov-msft amarinov-msft deleted the amarinov/appcontext-switch-disconnect-peer-v2 branch June 17, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants