Skip to content

[Windows] Guard HybridWebView init against a closed CoreWebView2 - #40796

Merged
kubaflo merged 1 commit into
mainfrom
fix-main-hybridwebview-windows-init-null
Nov 29, 2026
Merged

kubaflo merged 1 commit into
mainfrom
fix-main-hybridwebview-windows-init-null

Conversation

@kubaflo

@kubaflo kubaflo commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 86ff3df460c9b65517193fd7aac96e3778be24e2

Dimension Assessment Rationale
Change confidence 7/10 ↑ Minimal null guard on a path that currently throws; the non-null path is unchanged.
↑ Same change as #40771, merged to net11.
↓ Windows-only; not run locally (macOS host), CI is the validation.
Diagnosis confidence 8/10 ↑ main's maui-pr-uitests build 1703917 shows the same NullReferenceException at HybridWebViewHandler.Windows.cs:339 in TryInitializeWebView2 (HybridWebView category, exit 7), the line right after EnsureCoreWebView2Async.
↓ Why CoreWebView2 is null (control closed during init) is inferred from the code, not observed.
Evidence fit 7/10 ↑ Exact stack frame matches the guarded dereference.
↓ Not confirmed until maui-pr-uitests runs on this PR.

Target Branch

  • I selected the applicable base branch (main, .NET 12 fix).

Description of Change

TryInitializeWebView2 dereferenced webView.CoreWebView2 after EnsureCoreWebView2Async. If the control is closed while initialization is in flight, CoreWebView2 is null and the continuation throws a NullReferenceException on the dispatcher, which crashes the Windows device-test host (HybridWebView category, exit 7; maui-pr-uitests build 1703917 on main). Return false instead when it is null, matching the existing null handling in Disconnect.

Same fix as #40771, which merged to net11.

Validation: not run locally (Windows-only code); relies on CI.

Issues Fixed

Fixes the HybridWebView Windows device-test host crash on main.

)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `cdcaf4125975a7ea1c81ca95eeca4e2ef9018f02`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 6/10 | ↑ Minimal null guard, cannot regress the
non-null path.<br>↓ Not run: Windows-only, no Windows host available
locally. |
| Diagnosis confidence | 7/10 | ↑ CI log (maui-pr-uitests 1703818,
Windows controls unpackaged) shows NRE at
HybridWebViewHandler.Windows.cs:339 right after
EnsureCoreWebView2Async.<br>↓ Crash may also have other causes; no
causal red/green run. |
| Evidence fit | 7/10 | ↑ Stack trace matches the dereference of
CoreWebView2 after init.<br>↓ NavigationPage and Shell failures are not
explained by this change. |
<!-- /copilot-assessment -->

### Target Branch

- [x] I selected the applicable base branch (`net11`, .NET 11 fix, for
review).

### Description of Change

`TryInitializeWebView2` dereferenced `webView.CoreWebView2` after
`EnsureCoreWebView2Async`. If the control is closed while initialization
is in flight, `CoreWebView2` is null and the continuation throws a
`NullReferenceException` on the dispatcher, crashing the test host
(HybridWebView category, exit 7 in maui-pr-uitests 1703818). Return
`false` instead when it is null, matching the existing null handling in
`Disconnect`.

Validation: not run locally (Windows-only code); relies on CI.

### Issues Fixed

Fixes CI failure in HybridWebView Windows device tests on `net11`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 839a945)
@kubaflo

kubaflo commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@dalexsoto stamp

Copilot AI balanced review requested due to automatic review settings November 29, 2026 09:28
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 29, 2026 09:28 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 29, 2026 09:29 — with GitHub Actions Inactive
@azure-pipelines

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Queued JavaScript evaluations can remain permanently pending when initialization returns false, and the new closure-during-initialization path lacks regression coverage.

2 open issues
What changed in this PR

Adds a Windows-only guard to MAUI’s HybridWebView initialization to avoid dereferencing a null CoreWebView2 after asynchronous initialization. This brings the fix described in #40771 to main.

Changes:

  • Returns false when CoreWebView2 is null after initialization.
  • Leaves the successful initialization path unchanged.
File Description
src/​Core/​src/​Handlers/​HybridWebView/​HybridWebViewHandler.Windows.cs Adds a null guard before configuring WebView2 settings and events.

Review effort: Balanced

Comment on lines +340 to +342
if (webView.CoreWebView2 is null)
{
return false;
// The control can be closed or disconnected while initialization is in flight.
if (webView.CoreWebView2 is null)
{
return false;
kubaflo added a commit that referenced this pull request Nov 29, 2026
<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `4b5901591c54bd76752e588ac5582a05707a3207`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 7.5/10 | ↑ PR devicetests
[1704250](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704250):
iOS controls General 1493 total, 0 failed; log 303 shows iPhone 11 Pro /
iOS 27.2 selected.<br>↑ Local simulator runs: 14 scoped tests red → fix
green → reverted red → restored green.<br>↓ One green CI run of an
intermittent failure; other device-test suites not run locally. |
| Diagnosis confidence | 6/10 | ↑ Locally, the iPhone Duo profile
reproduces the failures without any predecessor test.<br>↓ main's device
step does not log the selected profile, so no CI log shows that failing
builds 1704212/1704247 used iPhone Duo. |
| Evidence fit | 6/10 | ↑ The same 17-test cluster fails intermittently
on unrelated PRs with the main tree, consistent with nondeterministic
device selection.<br>↓ Local Duo runs used iOS 27.1 and standard-phone
runs iOS 26.0; CI uses iOS 27.2, so this isn't a same-runtime
comparison. |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

<!-- Enter description of the fix in this section -->

The apparent intermittent iOS General cascade is **simulator-profile
drift, not a demonstrated TabbedPage state leak**.

The native device-test migration prefers iPhone 11 Pro / iPhone 16 but
falls back to any compatible phone on the newest installed runtime. A
device-specific runtime supporting only **iPhone Duo** therefore
silently changes this standard-phone lane to an unfolded, regular-width
navigation environment. The More-tab and native back-button assumptions
no longer hold; the tab-bar layer-removal assertion and ScrollView
geometry assertion also fail.

Select the newest installed runtime **together with a supported
standard-phone profile**, retaining the existing iPhone 11 Pro / iPhone
16 preferences. Do not fall back to an arbitrary device profile.
Explicit version/major requests remain within their requested version
range; when no supported standard-phone profile exists, report a
provisioning error instead of substituting another OS.

Log and persist the runtime identifier, version, build, and device type
in `device.json`. No product code, test assertion, skip, or category
exclusion changes.

**Coverage boundary:** a device-specific Duo runtime is not a
replacement for standard-phone coverage. This does not add foldable
coverage; that needs a separately configured lane. For `latest`, the
selected standard-phone runtime can be older than an installed Duo-only
runtime.

#### CI evidence

Actual simulator logs in the General job's published `DeviceTests`
artifact show:

| Build | General job | Device | Runtime |
| --- | --- | --- | --- |
|
[1704247](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704247)
| Failed, 17 victims | iPhone Duo / iPhone19,4 | iOS 27.2 / 24B91016s |
|
[1704240](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704240)
| Passed | iPhone 11 Pro / iPhone12,3 | iOS 27.2 / 24B8117 |
|
[1704155](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704155)
| Passed on main | iPhone 11 Pro / iPhone12,3 | iOS 27.2 / 24B8117 |

Each has 1,493 `TEST_START` events with different randomized order. In
1704247, the first failure starts at 14:32:39 UTC:
`BarBackgroundTransitionRemovesGradientAndRestoresEffect(True)`, with
`ArgumentNullException: collection`. The root-replacement tests do not
begin until 14:40:12 UTC, so they cannot explain that first failure. The
raw test-step log is 749 for 1704247, 736 for 1704240, and 781 for
1704155. The previously reported build 1704212/log 727 was no longer
readable; no claims are made about its ordering.

Before implementation, searched open and recently merged PRs across all
bases for the test names, More-navigation mechanisms,
`Start-TestDevice`, device-specific runtime selection, and iPhone Duo.
Inspected #40656, #40755, and #40766. The open siblings
#40799/#40800/#40801/#40802/#40805/#40796 do not implement this native
standard-phone runtime/profile selection correction.

#### Local causal validation

All results below come from **fresh native MTP TRX**, verified by the
existing runner for exact class/method isolation. Only owned iOS
simulators were used.

| Phase | Profile / runtime | Passed | Failed |
| --- | --- | --- | --- |
| Original | Duo / iOS 27.1, 24A94232 | 0 | 14 |
| Fixed | iPhone 11 Pro / iOS 26.0, 23A343 | 14 | 0 |
| Fix reverted exactly to main | Duo / iOS 27.1, 24A94232 | 0 | 14 |
| Fix restored | iPhone 11 Pro / iOS 26.0, 23A343 | 14 | 0 |

The 14 scoped victims cover all six tab-gradient variants, all six
failing More-transition variants, ScrollView, and the base
NavigationPage back-button variant. They reproduce **without running any
potential leaking predecessor**. Local exception messages match the CI
cluster, including `collection`, missing native back button, absent
shared-element flight, premature push completion, and navigation
timeout.

Commands, all from an isolated worktree off `origin/main` at
`1344d16421`:

```bash
export DOTNET_ROOT=/Users/kubaflo/Projects/copilot-worktrees/maui/kubaflo-catalyst-cascade/.dotnet
export PATH="$DOTNET_ROOT:$PATH"
# This installed preview SDK packages mlaunch under tools/lib, while its default property points at tools/bin.
export MlaunchPath="$DOTNET_ROOT/packs/Microsoft.iOS.Sdk.net12.0_27.1/27.1.12089-net12-p1/tools/lib/mlaunch/mlaunch.app/Contents/MacOS/mlaunch"
export RelativeMlaunchPath=packs/Microsoft.iOS.Sdk.net12.0_27.1/27.1.12089-net12-p1/tools/lib/mlaunch/mlaunch.app/Contents/MacOS/mlaunch
```

Preparation — **passed**, zero warnings/errors:

```bash
dotnet build Microsoft.Maui.BuildTasks.slnf --disable-build-servers -v:q
```

Causal run command — original used `-iOSVersion 27.1`;
fixed/reverted/restored used `-iOSVersion latest`, which selects that
same Duo runtime with the original selector. Results are listed in the
table above:

```bash
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \
  -Project Controls -Platform ios -iOSVersion latest \
  -IncludeClasses 'Microsoft.Maui.DeviceTests.TabbedPageTests,Microsoft.Maui.DeviceTests.TabbedPageTests_TabbedViewHandler,Microsoft.Maui.DeviceTests.TabbedPageNavigationHandlerTests,Microsoft.Maui.DeviceTests.NavigationPageTests,Microsoft.Maui.DeviceTests.PageTransitionsTests,Microsoft.Maui.DeviceTests.ScrollViewTests' \
  -IncludeMethods 'BarBackgroundTransitionRemovesGradientAndRestoresEffect,NavigatingBackViaBackButtonFiresNavigatedEvent,MoreTabNavigationsCompleteAfterTheTransition,MoreTabUnanimatedPushIsRecordedForThePop,MoreTabSharedElementFliesFromTheOverflowRoot,TestContentHorizontalOptionsChanged' \
  -SkipXcodeVersionCheck -Timeout 00:10:00 -DotnetPath "$DOTNET_ROOT/dotnet" \
  -OutputDirectory artifacts/ios-cascade/cluster-restored
```

Final expanded verification includes the three remaining NavigationPage
handler variants — **17 passed / 0 failed / 0 skipped**, covering every
reported victim:

```bash
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 \
  -Project Controls -Platform ios -iOSVersion latest \
  -IncludeClasses 'Microsoft.Maui.DeviceTests.TabbedPageTests,Microsoft.Maui.DeviceTests.TabbedPageTests_TabbedViewHandler,Microsoft.Maui.DeviceTests.TabbedPageNavigationHandlerTests,Microsoft.Maui.DeviceTests.NavigationPageTests,Microsoft.Maui.DeviceTests.NavigationPageNavigationHandlerTests,Microsoft.Maui.DeviceTests.NavigationPageTests_TabbedViewHandler,Microsoft.Maui.DeviceTests.NavigationPageTests_FlyoutViewHandler,Microsoft.Maui.DeviceTests.PageTransitionsTests,Microsoft.Maui.DeviceTests.ScrollViewTests' \
  -IncludeMethods 'BarBackgroundTransitionRemovesGradientAndRestoresEffect,NavigatingBackViaBackButtonFiresNavigatedEvent,MoreTabNavigationsCompleteAfterTheTransition,MoreTabUnanimatedPushIsRecordedForThePop,MoreTabSharedElementFliesFromTheOverflowRoot,TestContentHorizontalOptionsChanged' \
  -SkipXcodeVersionCheck -Timeout 00:10:00 -DotnetPath "$DOTNET_ROOT/dotnet" \
  -OutputDirectory artifacts/ios-cascade/full-cluster-final
```

Exact-version guard — **passed**: this real invocation rejects the
installed Duo-only 27.1 runtime with the expected provisioning error,
exit 1, without creating a simulator:

```bash
pwsh -NoProfile .github/skills/run-device-tests/scripts/Start-TestDevice.ps1 \
  -Platform ios -ApiVersion 27.1 \
  -ResultsDirectory artifacts/ios-cascade/exact-runtime-rejection \
  -DeviceDirectory artifacts/ios-cascade/exact-runtime-device
```

PowerShell parser validation and `git diff --check` — **passed**. No
pipeline unit/snapshot tests were added. The initial local launch
attempt did not run tests because of the preview SDK's missing
`tools/bin/mlaunch`; only subsequent runs using the explicit valid
launch path are counted. Full repository tests and PR CI have not been
run as validation evidence.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

The recurrent iOS Controls General cluster in the linked builds; no
unrelated issue-closing reference.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, the agent opens a follow-up PR that keeps your commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Nov 29, 2026
<!-- copilot-assessment:v1 -->
### Agent assessment

| Assessment | Evidence |
| --- | --- |
| Change confidence | Medium-high — ↑ Windows-only product change;
1704239 and 1704247 each passed 92 Shell tests in both Windows
modes<br>↑ Final head 1704247 passed 29 Window and 3 WindowOverlay tests
per mode, including real drawing and adorner attachment<br>↓ Full CI
remains red; iOS General and a Windows Entry mismatch are not dismissed
|
| Diagnosis confidence | Medium-high — ↑ Build 1704155 log and
crash.sequence.log identify SearchHandlerFocusTracksDetachment(True,
False)<br>↑ Downloaded native-process-4328.dmp contains 0x80070490
stowed stacks, symbolized using exact Microsoft PDB identities: Win2D
CanvasControl.OnLoaded → RegisterEventHandlers →
CoreApplication.add_Resuming → GetCurrentView; OnUnloaded →
UnregisterEventHandlers → remove_Resuming → GetViewFromTid<br>↓ Stowed
records establish the failing native mechanism, not the precise timing
of every focus/navigation operation |
| Evidence fit | ↑ Empty visual diagnostics overlays instantiate Win2D
CanvasControl from Loaded despite Visibility.Collapsed; dump has 14
VisualDiagnosticsOverlay/W2DGraphicsView objects<br>↑ Fix prevents this
unnecessary native lifecycle path without changing SearchHandler or
NavigationPage<br>↑ Builds 1704239 and 1704247: both Windows Shell
categories passed with zero failures/skips; final head also passed the
related Window/WindowOverlay categories<br>↓ Two runs strengthen but do
not prove elimination of an intermittent crash; broader CI has explicit
unmatched failures |

Head SHA: `63766cca9b0694b3d6039edd43a34729b8d697b7`
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

<!-- Enter description of the fix in this section -->

Keep an empty Windows window overlay out of the native visual tree until
it has something to draw. The public graphics view remains available,
and initialized/populated overlays still attach and draw. Once used, the
existing hide/show and teardown behavior remains unchanged.

This addresses the Windows Controls Shell host crash observed in [main
build
1704155](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704155),
also reported in 1704212. The log and sequence identify
`SearchHandlerFocusTracksDetachment(replaceSearchHandler: True,
disconnectHandler: False)`, but the dump's native stowed stacks point to
Win2D's application lifecycle callbacks—not the SearchHandler focus
callbacks. Collapsed controls still load, and `WindowHandler.MapContent`
initializes a hidden diagnostic overlay for every window.
`CoreApplication.GetCurrentView` / `GetViewFromTid` can return
ELEMENT_NOT_FOUND while the native view is unavailable.

The dump was downloaded and inspected on macOS. `dotnet-dump analyze`
explicitly rejects Windows dumps on macOS; LLDB opened it but could not
unwind useful native frames. Reading the minidump memory directly
recovered the native SE02 stowed exception records, then exact matching
Microsoft symbol-server PDBs resolved their addresses. The managed
COMException objects contain the same HRESULT but no managed stack
trace. The raw dump itself is not claimed as sufficient evidence.

The existing AdornerLayerAdded test now requests an actual adorner and
waits for its layer to load, instead of requiring an empty layer to be
attached. Tests preserve every SearchHandler focus/detachment case and
assert the diagnostic overlay stays detached. New Windows overlay cases
check empty initialization, first-element drawing, prepopulated
initialization and hiding after removal.

**Duplicate search:** checked open and recently merged PRs across main,
net11, release, candidate and inflight branches for the test,
ShellItemHandler, CanvasControl, Win2D and overlay mechanisms. #39779
added the focus coverage; #35079 added Windows focus requests. #40659 is
broader diagnostics trimming and switch/default work, not this native
attachment fix. #40802 owns NavigationPage continuation deferral and is
untouched; #40796 is untouched.

**Validation:**
- `git diff --check`: passed.
- `dotnet format Microsoft.Maui.sln --no-restore --include
src/Core/src/WindowOverlay/WindowOverlay.Windows.cs
src/Controls/tests/DeviceTests/Elements/Window/WindowOverlayTests.cs
src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs
--exclude Templates/src --exclude-diagnostics CA1822`: completed with
missing-reference workspace warnings; native compilation/formatting
coverage is not established.
- Windows tests cannot be built or run on this macOS host. Native PR CI
validation and the baseline comparison are recorded below.


### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

No linked issue; root-caused from device-test CI logs and crash
artifacts for builds 1704155 and 1704212.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, the agent opens a follow-up PR that keeps your commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->


### CI progression

- **1704237:** canceled before execution; not validation.
- **1704239**, initial head `16ba04224f3edf252a38b2a9a552906a724827bf`:
Windows packaged and unpackaged **Shell passed**; unpackaged
WindowOverlay **3 passed**, including populated rendering and
prepopulated initialization. Existing AdornerLayerAdded failed because
it assumed empty overlays were already attached; corrected in the latest
test-only commit.
- Both Windows Controls jobs still crash in
`NavigationPage.SettingTitleIconImageSourceDoesntCrash` (owned by
#40802). Windows Core
ReplacingVirtualViewUpdatesLayoutAndReleasesOldPress has the exact same
0x0 bounds failure as baseline 1704155 (owned by #40800).
- iOS Controls General had 17 failures in 1704239 (back-button lookup
and page-transition timing); baseline 1704155 was green. This is
explicitly **not** a clean cross-platform result; revalidation is
pending. All other completed iOS jobs passed; Catalyst Controls was
still running at collection time.


- **1704242:** Windows compilation exposed a missing explicit bool
argument on the IVisualDiagnosticsOverlay.AddAdorner interface call in
the updated test. Fixed with `AddAdorner(mainPage, false)`; this run is
**not** native validation. The wait now requires the native drawing
child itself to be loaded before teardown.


### Final native validation and baseline comparison

| Build | Head | Packaged Shell | Unpackaged Shell |
| --- | --- | --- | --- |
|
[1704239](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704239)
| Initial product fix `16ba04224f` | 92 passed, 0 failed/skipped | 92
passed, 0 failed/skipped |
|
[1704247](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704247)
| Final `63766cca9b` | 92 passed, 0 failed/skipped | 92 passed, 0
failed/skipped |

The product fix is identical across these two runs; subsequent commits
only corrected the directly related adorner test. The final merge SHA
was `4db1d797fdfcb4a16cd3c3ec7b2c10ba04f2208e`, validating PR head
`63766cca9b0694b3d6039edd43a34729b8d697b7`.

**Final head:** Window category **29 passed per Windows mode**;
WindowOverlay **3 passed per mode**, including populated/prepopulated
drawing. Unpackaged logs explicitly record all three
SearchHandlerFocusTracksDetachment cases. Evidence: 1704247 logs [736
(packaged)](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704247/logs/736)
and [752
(unpackaged)](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1704247/logs/752).
Both also report successful Shell TRX output.

**Evidence strength:** two green Shell runs per mode, exact symbolized
crash mechanism and focused regression coverage give materially stronger
evidence than a single retry. This is not statistical proof of
eliminating every possible intermittent crash.

**Broader CI is not all-green.** Against baseline 1704155 (all Apple
jobs green), final 1704247 has all five Catalyst jobs and seven of eight
iOS jobs green. iOS Controls General has **17 failures**, also seen in
1704239, involving tabbed bar backgrounds, ScrollView layout, overflow
page transitions and back-button lookup. These have no changed Apple
product path in this Windows-only fix, but remain **unmatched, needing
separate investigation**, not silently dismissed as known flakes. Final
unpackaged Windows also has an unmatched
Entry.UnFocusOnEntryAfterPagePop event-count assertion failure; it
passed in 1704239 and baseline 1704155. This is explicitly not a claim
of full cross-platform CI cleanliness.

The known NavigationPage native crash still occurs in both Windows modes
and belongs to #40802. Windows Core's ContentButton 0x0-layout assertion
matches baseline 1704155 exactly and belongs to #40800. No changes from
either sibling fix were duplicated.

---------

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

kubaflo commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@dalexsoto stamp

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stamping as requested by @kubaflo; no code review performed.

@kubaflo
kubaflo merged commit 9c4919b into main Nov 29, 2026
46 of 50 checks passed
@kubaflo
kubaflo deleted the fix-main-hybridwebview-windows-init-null branch November 29, 2026 17:10
kubaflo added a commit that referenced this pull request Nov 29, 2026
…evice-test waits (#40818)

<!-- copilot-assessment:v1 -->
### Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: `3eec8791098beea08fbb2e411202fb58d7d1c435`

| Dimension | Assessment | Rationale |
|---|---|---|
| Change confidence | 8/10 | ↑ Final-head device-test build 1704477
succeeded; HybridWebView passed in both Windows modes (104 passed, 4
skipped each). All three regression tests executed in the unpackaged
log. The existing polling harness passes 3/3 locally.<br>↓ Two
successful runs per mode cannot eliminate an intermittent native
initialization failure. |
| Diagnosis confidence | 7/10 | ↑ WinUI catches controller-creation
errors and reports them through CoreWebView2Initialized, so
EnsureCoreWebView2Async can complete with a null core; the old
false-result path drops JavaScript requests.<br>↓ Build 1704369 did not
record the native error; teardown/shared-environment causality is not
established. |
| Evidence fit | 8/10 | ↑ Raw logs in builds 1704453 and 1704477 confirm
four passing Windows HybridWebView category executions, including the
previously stalled Invoke_NoParam_ReturnTaskComplex and focused
failure-path tests.<br>↓ This is bounded-failure protection and improved
diagnostics, not proof that the underlying native failure has been
eliminated. |
<!-- /copilot-assessment -->

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

<!-- Enter description of the fix in this section -->

Follow-up to #40796, not a revert. Keep the null-core guard, but
distinguish a disconnected handler from an initialization failure:

- Capture the native error from `CoreWebView2Initialized`, fault the
ready task, and retain the error as the inner exception.
- Propagate failed initialization (including a false ready result) to
`EvaluateJavaScriptAsync` instead of abandoning its completion source.
- Log failures in fire-and-forget navigation/raw-message operations
without an unhandled dispatcher exception.
- Do not navigate or subscribe events for a disconnected or replaced
platform view after asynchronous initialization.
- Bound HybridWebView page/status polling, including an individual
JavaScript evaluation that never completes. Bound test operations
separately.
- Add three focused regression cases for faulted initialization, false
initialization, and a stalled polling evaluation. Adapt the existing
source-polling Pester harness to the helper's internal visibility and
cancellation-token dependency.

**Evidence:** [build
1704369](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704369),
raw log 836, Windows controls unpackaged. Last `TEST_START` at 18:05:48Z
is `Invoke_NoParam_ReturnTaskComplex`; no further test progress precedes
the task timeout at 19:47:16Z. Packaged passed in that build; the six
preceding supplied builds passed HybridWebView in both Windows jobs.
This is one occurrence, not proof that #40796 caused the underlying
native failure.

**Why a null core does not prove teardown:** [WinUI
WebView2.cpp](https://github.com/microsoft/microsoft-ui-xaml/blob/main/controls/dev/WebView2/WebView2.cpp),
`CreateCoreWebViewFromEnvironment`, catches `hresult_error`, fires
`CoreWebView2Initialized(hr)`, and completes its coroutine.
`EnsureCoreWebView2Async` awaits that operation. No native HRESULT was
recorded in the failing run, so this PR exposes it rather than guessing
at an environment workaround or adding blind retries.

**Duplicate check:** searched open/recent PRs for HybridWebView Windows,
EnsureCoreWebView2Async, and CoreWebView2 null. #40796/#40771 add the
valid null guard; #38569 handles regular WebView; #36742 fixes a
memory-test initialization wait. No open duplicate addressing
HybridWebView failure propagation and bounded waits was found.

**Validation**

- `git diff --check` — passed.
- `dotnet format Microsoft.Maui.sln --no-restore --include
src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.Windows.cs
src/Core/src/Platform/Windows/MauiHybridWebView.cs
src/Controls/tests/DeviceTests/Elements/HybridWebView/HybridWebViewTestsBase.cs
src/Controls/tests/DeviceTests/Elements/HybridWebView/HybridWebViewTests_EvaluateJavaScriptAsync.cs
src/Controls/tests/DeviceTests/Elements/HybridWebView/HybridWebViewTests_EvaluateJavaScriptAsync.Windows.cs
--exclude Templates/src --exclude-diagnostics CA1822 --verbosity quiet`
— completed successfully; formatting, not Windows compilation.
- `pwsh -NoProfile -Command '$c = New-PesterConfiguration; $c.Run.Path =
"./eng/devices/Direct-TestDevice.Tests.ps1"; $c.Filter.FullName =
"HybridWebView startup polling budget*"; $c.Run.Exit = $true;
$c.Output.Verbosity = "Detailed"; Invoke-Pester -Configuration $c'` —
passed, 3/3.
- Windows tests are not run locally (macOS host). Requested `/azp run
maui-pr-devicetests`.
- **[Final-head build
1704477](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704477)
succeeded.** Its tested merge `b5b01d2dc0a35d5763f3e108f320ebfc0ce7e0ad`
has PR head `3eec8791098beea08fbb2e411202fb58d7d1c435` as a parent. Both
Windows controls jobs succeeded. Packaged raw log 777 and unpackaged raw
log 747 each report **HybridWebView 104 succeeded / 0 failed / 4
skipped**. Unpackaged logs show the three new tests at 20:58:15–17Z and
`Invoke_NoParam_ReturnTaskComplex` at 20:59:08Z, followed by the
successful summary at 20:59:53Z. Packaged completes the category at
21:01:07Z.
- [Build
1704453](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1704453),
product/test revision `49ef2ab01b92e20a7b6115a87323241761d04e4f`:
packaged raw log 747 and unpackaged raw log 771 each report
**HybridWebView 104 succeeded / 0 failed / 4 skipped**. The entire build
failed because unpackaged Entry failed `UnFocusOnEntryAfterPagePop`
(`EntryTests.cs:186`); no Entry code was changed. Entry passes in the
final-head build.
- First admission 1704451 was canceled before execution. Each requested
run needed a second `/azp run maui-pr-devicetests` comment before
admission.
- Full Pester on the first revision failed: three source-polling tests
were directly affected by the extraction signature and are now
repaired/locally validated. Other reported release/pipeline/model-policy
failures concern files outside this diff. The overall PR still has a
failing Pester check; no claim that every required check is green.

Two successful runs in each Windows mode are useful evidence, not proof
against a rare recurrence. The underlying native initialization error
remains unknown.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Relates to #40796. Addresses the Windows HybridWebView device-test hang
in build 1704369; no separate issue has been filed.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, the agent opens a follow-up PR that keeps your commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

---------

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

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 86ff3df4 Deployed Nov 29, 2026 by kubaflo via conclusion #3466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants