Skip to content

fix(win32): Correct UIA structure event ABI (backport #25985) - #26025

Closed
mergify[bot] wants to merge 6 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25985
Closed

mergify[bot] wants to merge 6 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25985

Conversation

@mergify

@mergify mergify Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: related to unoplatform/kahua-private#564

PR Type:

🐞 Bugfix

What changed? 🚀

1. Structure-event ABI (the crash). While a UI Automation client is subscribed to structure changes, removing an element can crash in UiaRaiseStructureChangedEvent with an access violation (0xC0000005). The native signature is (IRawElementProviderSimple*, StructureChangeType, int* pRuntimeId, int cRuntimeIdLen). Our P/Invoke marshalled the runtime ID as a SAFEARRAY and omitted the length, so only ChildRemoved, which carries a runtime ID, crashed. The P/Invoke now passes an int[] plus its length, and 0 for a null runtime ID. No other P/Invoke in Win32UIAutomationInterop.cs has this mistake: UiaRaiseTextEditTextChangedEvent really does take a SAFEARRAY*.

2. Lookups during provider cleanup (behaviour change). UiaDisconnectProvider calls back into the provider it is disconnecting: ProviderOptions, HostRawElementProvider, GetPropertyValue, Navigate(Parent), GetRuntimeId and FragmentRoot. It does this even when no client has subscribed to the app's events. Navigate(Parent) resolves the parent through GetProviderForPeer / GetOrCreateProvider. On master these lookups returned null while CleanupProviders ran, even for a parent whose provider was still connected.

During cleanup, the three lookups (GetOrCreateProvider, GetProvider, GetOrCreateProviderForResolvedPeer) now share one lookup-only path:

  • They try the peer key first, then the owner's element key, and accept the element-keyed provider only when it represents the same peer.
  • They never create a peer or a provider, and they never write the lookup tables.

Creation stays blocked during cleanup, so a callback can't create a provider for an element that was just cleaned.

3. CI coverage of the ABI fix. When_Native_Client_Observes_Structure_Changes needs an out-of-process UIA client. A regular runtime-test run therefore reports it as inconclusive. The Windows Skia runtime-test job now runs build/test-scripts/Win32UiaEventProbe after the main run and publishes its results.

Validation

Runtime (Skia Win32, local, Given_Win32ProviderLifetime):

Build Regular run With Win32UiaEventProbe
This PR 5 passed, 1 inconclusive 6/6 passed; ChildAdded and ChildRemoved matched the runtime ID
Signature reverted to the SAFEARRAY form 5 passed, 1 inconclusive (green) the app crashed with 0xC0000005, and the probe failed
Cleanup lookup before the lookup-only change When_Cleanup_Reenters_Live_Provider_Lookup failed (provider registered only by its peer) —

Compile: desktop SamplesApp, Release net10.0-desktop.

Earlier evidence from the 6.x lines:

  • Unpatched servicing/6.8 crashed with 0xC0000005 in the three-argument call under the same subscription.
  • Retained owners and a missed redirected-peer provider also reproduced on servicing/6.8. Their fix (the provider cleanup from feat(a11y): WinUI-parity accessibility fixes for Skia (Win32/macOS/WASM) #23722) is already on master, not in this PR.
  • The prepared servicing/6.8 and release/stable/6.7 candidates passed 6/6 with the probe.

Not resolved by this PR: the Kahua retention. In the Kahua desktop app (Uno.WinUI 6.7.135 with the patched 6.7 Win32 runtime), Close Record Detail unloads the view. The view's weak reference still survives repeated full GC and finalizer waits, even after the native client detaches (36 structure events received). That retention is tracked separately on the issue. This PR fixes the crash and the cleanup lookups, so it does not close the issue.

To run the native regression locally after building SamplesApp:

dotnet run --project build/test-scripts/Win32UiaEventProbe -- <absolute-path-to-SamplesApp.dll> <absolute-path-to-results.xml>

Backports: release/stable/7.0 via Mergify. servicing/6.8 and release/stable/6.7 get separate PRs: the 6.x code differs, and those PRs also carry the provider-cleanup part of #23722.

PR Checklist ✅


This is an automatic backport of pull request #25985 done by [Mergify](https://mergify.com).

morning4coffe-dev and others added 6 commits November 4, 2026 10:14
UiaDisconnectProvider calls back into the provider it disconnects,
including Navigate(Parent), even when no UIA client has subscribed to
the app's events. While CleanupProviders runs,
GetOrCreateProviderForResolvedPeer still checked the cleanup gate
before its element-keyed match and could create a peer and write the
lookup tables (RegisterPopupPanelAlias), while GetOrCreateProvider and
GetProvider tried only the element key, missing providers registered
by peer.

During cleanup all three now use one lookup: the peer key, then the
owner's element key when its provider represents the same peer. It
never creates a peer or a provider and never registers an alias.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e4c9bfc)
Delete the probe's marker folder when it finishes, correct the comment
on why the client runs out of process, and join the marker paths with
Path.Join in the runtime test too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 973de7a)
When_Native_Client_Observes_Structure_Changes is inconclusive without
an out-of-process UIA client, so restoring the SAFEARRAY signature of
UiaRaiseStructureChangedEvent passed every runtime test. Run
Win32UiaEventProbe after the Windows Skia runtime tests and publish its
results. Locally, with the signature reverted, the probe fails with the
access violation (0xC0000005) while the regular run stays green.

CI installs only the .NET 11 SDK, so the probe rolls forward to the
next major runtime, as Uno.NUnitTransformTool does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 068ed8f)
@github-actions github-actions Bot added area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation labels Nov 4, 2026
@mergify mergify Bot mentioned this pull request Nov 4, 2026
4 of 5 tasks
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243534 did not find any UI Test snapshots differences.

@MartinZikmund

Copy link
Copy Markdown
Member

Auto synced

@MartinZikmund
MartinZikmund deleted the mergify/bp/release/stable/7.0/pr-25985 branch November 12, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants