Add AppContext switch to guard automation peer disconnect behavior#11723
Closed
amarinov-msft wants to merge 1 commit into
Closed
Add AppContext switch to guard automation peer disconnect behavior#11723amarinov-msft wants to merge 1 commit into
amarinov-msft wants to merge 1 commit into
Conversation
4659075 to
ee49533
Compare
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>
ee49533 to
17a9e80
Compare
gpaskaleva-msft
approved these changes
Jun 15, 2026
Author
|
Closing the PR as this will be addressed in #11657 |
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.
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
ElementNotAvailableExceptioninstead 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