Skip to content

appcontext switch disconnect peer#11722

Closed
amarinov-msft wants to merge 18 commits into
pr-11657from
amarinov/appcontext-switch-disconnect-peer
Closed

appcontext switch disconnect peer#11722
amarinov-msft wants to merge 18 commits into
pr-11657from
amarinov/appcontext-switch-disconnect-peer

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 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

mthalman and others added 18 commits May 14, 2026 12:35
* Fix potential overflow issues in WPF native code

* Resolving Comments
…otnet-wpf-int build 20260520.1 (#11653)

[main] Update dependencies from dnceng/internal/dotnet-wpf-int
* Add dotnet-wpf-maintainers to CODEOWNERS

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Backflow from https://github.com/dotnet/dotnet / 5f66bab build 314998

Diff: https://github.com/dotnet/dotnet/compare/2d7b4831c91f7990963db74cfc4c08899cf0c2fd..5f66bab627b918f4a101caea5eebbe9321fbf9fe

From: dotnet/dotnet@2d7b483
To: dotnet/dotnet@5f66bab

[[ commit created by automation ]]

* Update dependencies from build 314998
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk, Microsoft.DotNet.CodeAnalysis, Microsoft.DotNet.GenAPI, Microsoft.DotNet.Helix.Sdk (Version 11.0.0-beta.26229.113 -> 11.0.0-beta.26269.105)
Microsoft.Dotnet.WinForms.ProjectTemplates, Microsoft.NETCore.App.Ref, Microsoft.NETCore.Platforms, Microsoft.Private.Winforms, System.CodeDom, System.Configuration.ConfigurationManager, System.Diagnostics.EventLog, System.DirectoryServices, System.Drawing.Common, System.Formats.Nrbf, System.IO.Packaging, System.Private.Windows.Core.TestUtilities, System.Reflection.MetadataLoadContext, System.Resources.Extensions, System.Runtime.Serialization.Formatters, System.Security.Cryptography.Xml, System.Security.Permissions, System.Windows.Extensions (Version 11.0.0-preview.5.26229.113 -> 11.0.0-preview.5.26269.105)
[[ commit created by automation ]]

* Updating test dependencies to avoid failures during test runs (#11655)

* User/dipesh/fixing test dependencies v2 (#11658)

* Updating test dependencies to avoid failures during test runs

* Fixing test failure due to xUnit dependency updates

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Dipesh Kumar <85861525+dipeshmsft@users.noreply.github.com>
* Backflow from https://github.com/dotnet/dotnet / 1616fce build 316157

Diff: https://github.com/dotnet/dotnet/compare/4386cd647217cd4055737aedef6a895bb53f7f79..1616fce88662817fb8b76911fb188b56650859a0

From: dotnet/dotnet@4386cd6
To: dotnet/dotnet@1616fce

[[ commit created by automation ]]

* Update dependencies from build 316157
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk, Microsoft.DotNet.CodeAnalysis, Microsoft.DotNet.GenAPI, Microsoft.DotNet.Helix.Sdk (Version 11.0.0-beta.26269.105 -> 11.0.0-beta.26277.116)
Microsoft.Dotnet.WinForms.ProjectTemplates, Microsoft.NETCore.App.Ref, Microsoft.NETCore.Platforms, Microsoft.Private.Winforms, System.CodeDom, System.Configuration.ConfigurationManager, System.Diagnostics.EventLog, System.DirectoryServices, System.Drawing.Common, System.Formats.Nrbf, System.IO.Packaging, System.Private.Windows.Core.TestUtilities, System.Reflection.MetadataLoadContext, System.Resources.Extensions, System.Runtime.Serialization.Formatters, System.Security.Cryptography.Xml, System.Security.Permissions, System.Windows.Extensions (Version 11.0.0-preview.5.26269.105 -> 11.0.0-preview.6.26277.116)
[[ commit created by automation ]]

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
… Build ID 2994624 (#11646)

* Localized file check-in by OneLocBuild Task: Build definition ID 217: Build ID 2977651

* Localized file check-in by OneLocBuild Task: Build definition ID 217: Build ID 2977651

* Localized file check-in by OneLocBuild Task: Build definition ID 217: Build ID 2977651
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
[main] Source code updates from dotnet/dotnet
* Package ijwhost.dll as native asset for self-contained publish

After the /clr:pure to /clr:NetCore migration (#11575), DirectWriteForwarder
and System.Printing became mixed-mode C++/CLI assemblies that require
ijwhost.dll at runtime. The DLL was being placed in the managed lib/ folder
where it is not recognized by RuntimeList.xml, causing it to be missing from
self-contained publish output.

Exclude ijwhost.dll from the lib/ packaging and add it as a native asset
under runtimes/win-{arch}/native/ so it is properly included in the runtime
pack manifest.

Fixes #11651

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

* Move ijwhost.dll packaging logic to Packaging.targets

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
[main] Source code updates from dotnet/dotnet
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

The DisconnectPeerFromUia implementation (from PR #11717) is guarded by
checking !CoreAppContextSwitches.UseLegacyAutomationPeerDisconnect at both
call sites: EnsureChildren and UpdateChildrenInternal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@amarinov-msft amarinov-msft requested a review from a team as a code owner June 15, 2026 12:21
@amarinov-msft amarinov-msft changed the title Amarinov/appcontext switch disconnect peer appcontext switch disconnect peer Jun 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the PR metadata: Label to tag PRs, to facilitate with triage label Jun 15, 2026
@amarinov-msft amarinov-msft deleted the amarinov/appcontext-switch-disconnect-peer branch June 15, 2026 12:25
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.

6 participants