Repository navigation
[Windows] WebView: Guard failed WebView2 initialization - #38569
Conversation
Check initialization errors and the native core before subscribing to WebView2 events. Log the original initialization exception without raising a secondary NullReferenceException. Fixes #38527 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38569Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38569" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
Exercise the full initialization callback through an internal seam with a real uninitialized WebView2 and both exception/no-exception inputs. Assert diagnostic preservation and safe cleanup without process-wide runtime overrides. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@jfversluis — new AI review results are available based on commit
ded289b.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: WINDOWS · Base: main · Merge base: 1cd2e15b
✅ Verified (new API / feature) — this PR adds new API and a test that references it in the same project, so reverting the fix un-compiles the test: there is no valid "fails without the fix" baseline to establish (a compile-coupled baseline). The gate instead verified the fix by a clean build + pass with the fix, so this is a real PASS rather than a non-committal INCONCLUSIVE.
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
📱 WebViewHandlerTests (FailedCoreWebView2InitializationLogsErrorWithoutThrowing) Category=WebView |
🛠️ BUILD ERROR | ✅ PASS — 302s |
🔴 Without fix — 📱 WebViewHandlerTests (FailedCoreWebView2InitializationLogsErrorWithoutThrowing): 🛠️ BUILD ERROR · 269s
Error-relevant lines (filtered from the build log):
D:\a\1\s\src\Core\tests\DeviceTests\Handlers\WebView\WebViewHandlerTests.Initialization.Windows.cs(34,14): error CS1061: 'WebViewHandler' does not contain a definition for 'ProcessCoreWebView2Initialized' and no accessible extension method 'ProcessCoreWebView2Initialized' accepting a first argument of type 'WebViewHandler' could be found (are you missing a using directive or an assembly reference?) [D:\a\1\s\src\Core\tests\DeviceTests\Core.DeviceTests.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Build FAILED.
🟢 With fix — 📱 WebViewHandlerTests (FailedCoreWebView2InitializationLogsErrorWithoutThrowing): PASS ✅ · 302s
(no coded error found; showing last 1200 chars)
uppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:04:24.94
Passed: 2
Failed: 0
Skipped: 0
Total: 2
Tests completed successfully
⚠️ Failure Details
- 🛠️ WebViewHandlerTests (FailedCoreWebView2InitializationLogsErrorWithoutThrowing) without fix: build failed before tests could run
D:\a\1\s\src\Core\tests\DeviceTests\Handlers\WebView\WebViewHandlerTests.Initialization.Windows.cs(34,14): error CS1061: 'WebViewHandler' does not contain a definition for 'ProcessCoreWebView2Initiali...
📁 Fix files reverted (1 files)
src/Core/src/Handlers/WebView/WebViewHandler.Windows.cs
📋 Pre-Flight — Context & Validation
PR #38569 Pre-Flight
Context
- PR:
[Windows] WebView: Guard failed WebView2 initialization - Issue: #38527,
NullReferenceException in WebViewHandler.Windows.cs OnCoreWebView2Initialized when WebView2 initialization fails - Base/head:
mainat1cd2e15b/ PR headded289b4; locally materialized as squashed review commit300496d7 - Platform: Windows
- Gate: Passed previously. Do not rerun gate verification and do not modify
gate/content.md.
WinUI raises CoreWebView2Initialized for unsuccessful initialization as well as success. In the base implementation, the callback dereferences sender.CoreWebView2 four times to subscribe to native events. On failure, CoreWebView2 can be null, so this produces a secondary NullReferenceException that obscures the original initialization failure.
PR Diff Assessment
The PR changes two files:
src/Core/src/Handlers/WebView/WebViewHandler.Windows.cs(+19/-4)- Adds an internal
ProcessCoreWebView2Initializedtest seam. - Forwards
CoreWebView2InitializedEventArgs.Exceptionfrom the native callback. - Returns when the exception is non-null or
sender.CoreWebView2is null. - Logs
Failed to initialize WebView2.at Error level through the handler logger. - Captures the non-null
CoreWebView2instance and uses it for the four native subscriptions.
- Adds an internal
src/Core/tests/DeviceTests/Handlers/WebView/WebViewHandlerTests.Initialization.Windows.cs(+62, new file)- Adds two theory rows covering failure with and without an exception.
- Invokes the internal seam and verifies no throw, a null native core, and one Error log preserving the supplied exception.
The existing fix therefore combines the production guard with a test-only internal seam. Alternative candidates must use a different mechanism/root-cause strategy, not merely move the same null/exception guard to another line.
Baseline and Modification Boundary
The prior gate restored only:
src/Core/src/Handlers/WebView/WebViewHandler.Windows.cs
The newly added test is compile-coupled to the internal seam and must remain read-only. Each try-fix invocation must establish and restore its baseline only through .github/scripts/EstablishBrokenBaseline.ps1. The repository also contains unrelated pre-existing tracked and untracked harness changes; preserve them.
Targeted Validation
Run only:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Core -Platform windows -TestFilter "Category=WebView"The detected primary regression is WebViewHandlerTests.FailedCoreWebView2InitializationLogsErrorWithoutThrowing, whose two rows passed with the PR fix. No additional mandatory regression tests were supplied in the STEP 5a request; do not run a full suite.
Candidate Constraints
- One implementation/test pass per candidate, with at most one focused correction and retest.
- Candidate 2 must read Candidate 1's recorded result and avoid its mechanism.
- Inline expert self-review only; do not launch a reviewer agent.
- Always capture artifacts and restore the baseline before returning, including on failure or blockage.
🔬 Code Review — Deep Analysis
Expert Evaluation of the Submitted PR
Result
- Expert verdict:
NEEDS_DISCUSSION - Confidence: Low
- Actionable inline findings: None (
inline-findings.jsoncontains[]) - Reason for the non-LGTM verdict: Required-check status could not be retrieved in the review environment. The reviewer found no validated code defect in the submitted diff; this verdict reflects undetermined CI rather than a requested source change. The separately trusted Gate for this workflow passed.
Independent Assessment
The Windows WebView handler now forwards the native WebView2 initialization exception into an internal processing method. That method returns before native event subscription when initialization supplied an exception or did not produce a CoreWebView2, logging the original failure when a handler logger is available. On successful initialization it captures the non-null core and subscribes to the same four native events as before.
This prevents the secondary NullReferenceException that previously occurred when WinUI raised CoreWebView2Initialized after failed initialization. The implementation is localized to the Windows handler callback, introduces no public API or shared/static state, and retains the initialization subscription so a later initialization attempt can still succeed.
Test and Lifecycle Assessment
The submitted Windows device test exercises the production processing method with a real uninitialized WebView2, both with and without a supplied exception. It verifies normal return, a null core, and one Error log preserving the supplied exception. The trusted Gate independently established that the regression fails without the fix and passes with it.
Failure-mode probing found no concrete defect:
- Failed initialization exits before dereferencing or subscribing to a null core.
- A later successful initialization remains possible because the outer initialization callback stays subscribed until disconnect.
- Disconnect still removes the initialization callback and any successful-path core subscriptions.
- An absent handler, context, service provider, or logger does not turn logging into another failure.
Prior Review and CI Reconciliation
The prior critical review comment requested regression coverage. It is obsolete at the current submitted HEAD because the PR now includes the targeted Windows regression test. No unresolved prior Error-level finding was found across top-level reviews, inline review comments, or issue comments.
The expert could not retrieve current required-check state because authenticated GitHub CLI access was unavailable and the anonymous API fallback was rate-limited. Under the code-review rubric this makes CI status undetermined and caps the formal expert verdict at NEEDS_DISCUSSION; it does not identify an implementation flaw or actionable reviewer patch.
🛠️ Try-Fix — Analysis & Comparison
PR #38569 - Alternative Try-Fix Aggregate
Candidate 1 - Success-Confirmed Subscription Ownership
Model: gpt-5.3-codex
Result: Blocked
Test runs: 0
Files changed: None
Self-review: 0 findings
Approach
Preserve the compile-coupled ProcessCoreWebView2Initialized(WebView2, Exception?) signature, but move native CoreWebView2 event subscriptions out of the initialization-failure callback flow and into a success-confirmed core-ready path.
Existing Mechanism Avoided
The PR keeps subscription work in ProcessCoreWebView2Initialized and protects it with exception is not null || CoreWebView2 is null before logging and returning. Candidate 1 instead proposed changing ownership and timing of subscription work rather than placing another guard around the same dereferences.
Mechanism-Level Difference
Failure callback handling would never perform subscription work. A separate success-confirmed path would own subscriptions only after a native core exists, eliminating callback-time null dereferences through lifecycle separation rather than a null/exception condition at the failing call site.
Diff
(no changes)Test Result and Failure Analysis
The required command was not run:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Core -Platform windows -TestFilter "Category=WebView"EstablishBrokenBaseline.ps1 rejected the extensive pre-existing tracked workspace changes and did not create .github/.baseline-state.json. Without the script-generated RevertedFiles allow-list, tracked edits were prohibited. The exact restore command ran and reported the valid no-state outcome Restored False / No baseline state found. This result is a protocol/environment block, not a mechanism verdict.
Candidate 2 - Try-Fix Attempt 2 (PR #38569)
Status
Blocked
Approach
Preserve ProcessCoreWebView2Initialized(WebView2, Exception?), but model WebView2 initialization as one fallible operation: normalize either a supplied initialization exception or a missing native core into the method's exception path, catch that initialization failure at the seam boundary, log the original supplied exception, and return before subscriptions. Successful initialization would continue with the resolved core in the existing callback.
Existing PR Mechanism Avoided
The PR uses an explicit compound precondition guard (exception is not null || sender.CoreWebView2 is not CoreWebView2) to log and return before subscriptions. Candidate 2 does not use that predicate-based suppression mechanism; it represents invalid initialization as a controlled operation failure handled by an exception boundary.
Candidate 1 Mechanism Avoided
Candidate 1 proposed moving all native subscription ownership out of the failure callback into a separate success-confirmed core-ready lifecycle path. Candidate 2 keeps subscription ownership in the existing initialization callback and therefore does not repeat lifecycle-separated or success-path ownership.
Mechanism-Level Difference
The native callback is treated as an exception boundary that converts WebView2's inconsistent failure signals (event exception and/or absent core) into one controlled failure channel. That channel exits before native event wiring, preventing a null-core dereference without the PR's compound failure guard; the successful path retains callback-local event wiring rather than moving it to Candidate 1's separate lifecycle path.
Files Changed
None. Baseline establishment failed before tracked edits were permitted.
Full Captured Diff
(no changes)Test Command and Result
Required command:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Core -Platform windows -TestFilter "Category=WebView"Test runs: 0. The command was not executed because baseline establishment failed before a safe modification allow-list existed. test-output.log records that blocked outcome; there is no device-test output.
Failure Analysis
EstablishBrokenBaseline.ps1 rejected extensive pre-existing tracked workspace changes and created no .github/.baseline-state.json. Per the baseline-file boundary, absence of that state is an immediate Blocked result: no production file could be edited, and testing an unimplemented candidate would not provide candidate evidence. This is a protocol/environment block, not a verdict on the exception-boundary mechanism.
Self-Review
Count: 0 findings. No candidate diff existed. The inline review applied the eight overarching principles and the routed Handler/Architecture/Public API, Logic and Correctness, Regression Prevention, Null Safety, Windows, Input/Path, and Complexity Reduction checks. reviewer-findings.json contains [], and reviewer-findings.diff is empty.
Restore Confirmation
The exact command pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore ran after artifact capture and reported Restored False / No baseline state found. This is the narrowly allowed no-state blocked outcome: establishment created no state and no attempt edits were made.
🏁 Report — Final Recommendation
✅ Final Recommendation: APPROVE
Winner: pr (the raw submitted fix).
The submitted PR is the only distinct, implemented candidate backed by the trusted Gate: the regression fails without the fix and passes with it. The single expert review found no actionable source issue, produced an empty inline-findings.json, and confirmed that the earlier critical request for regression coverage is resolved at the current HEAD.
Comparative Ranking
| Rank | Candidate | Implementation | Regression evidence | Expert assessment | Result |
|---|---|---|---|---|---|
| 1 | pr |
Complete guard, diagnostic logging, success-path subscriptions, and targeted Windows test | Gate passed: tests fail without the fix and pass with it | No actionable finding or unresolved prior Error-level issue | Winner |
| 2 | pr-plus-reviewer |
Byte-for-byte equivalent to pr; reviewer patch is empty |
Same production/test implementation as the Gate-passing PR; no candidate-only validation was needed | Reviewer recommended no source refinement | Equivalent but offers no improvement |
| 3 | try-fix-1 |
Not implemented; proposed moving subscription ownership to a separate success-confirmed path | No test run; blocked before edits | No diff to assess | Blocked |
| 4 | try-fix-2 |
Not implemented; proposed normalizing failure into an exception-boundary path | No test run; blocked before edits | No diff to assess; concept adds exception-driven control flow without demonstrated benefit | Blocked |
Why pr Wins
The raw PR directly addresses the native contract: CoreWebView2Initialized can report failure with an exception and/or a missing core. It exits before dereferencing the missing core, preserves the original exception in an Error log, and retains the existing successful initialization and disconnect lifecycle. Its checked-in test covers both failure signal shapes through the production processing path.
pr-plus-reviewer cannot outrank pr because the expert found nothing actionable to apply; it is not a distinct implementation. Selecting it would falsely imply that reviewer changes are required. Both try-fix-* entries are design sketches with no candidate diff and no validation because baseline establishment was blocked. Regardless of conceptual merit, an unimplemented and untested proposal ranks below the implemented candidate whose regression test passed.
Risk and Uncertainty
The change is localized to Windows WebView handler initialization, adds no public API or shared/static state, and preserves event unsubscription. The expert reviewer could not retrieve live required-check status because GitHub authentication was unavailable and the anonymous API was rate-limited, so its formal confidence was capped at low by the review rubric. That environment gap does not identify a code defect; for this comparative decision, the supplied trusted Gate explicitly permits approval and provides the required fail-without/pass-with evidence.
📱 UI Tests — ViewBaseTests
Detected UI test categories: ViewBaseTests
[!WARNING]
No UI test results were produced for the detected categories. The PR build itself was
fine — the deep UI stage was skipped or interrupted on infrastructure (the
merge-for-testing step, emulator/simulator boot, or an Appium hang), not by this PR's code.
This is usually transient; the review re-runs on new commits (a maintainer can also re-run it).
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
<!-- 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! ### Description of Change WinUI raises `CoreWebView2Initialized` for failed initialization as well as success. `WebView2Proxy.OnCoreWebView2Initialized` previously dereferenced `sender.CoreWebView2` unconditionally, producing a secondary `NullReferenceException` when initialization failed and the core was null. Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt. The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an `InvalidOperationException`, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes. This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate `MauiWebView.LoadHtml` / local `LoadUrl` async error-handling paths. ### Validation **Checked-in regression coverage:** `WebViewHandlerTests.Initialization.Windows.cs` adds `FailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)` with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure. The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter: | Test execution | Result | | --- | --- | | Separate source snapshot with only the guard removed and the seam retained | Both rows fail with `NullReferenceException`; process exit 10 | | Fixed linked handler source, identical test body and fixture adapter | Both rows pass; exit 0 | | Actual fixed Release `Microsoft.Maui.dll` | Both rows pass; exit 0 | This is supplemental **guard-removal mutation evidence**, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs. **Genuine native reproduction:** a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing `WEBVIEW2_BROWSER_EXECUTABLE_FOLDER` is set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies. | Native case | Before | After | | --- | --- | --- | | Missing runtime | `FileNotFoundException` (`0x80070002`), null core, secondary callback NRE | Original failure remains; no secondary NRE | | Successful initialization and navigation | Callback completes normally | Navigation reaches `VirtualView.Navigated(..., Success)` | | Failure diagnostics and cleanup | Secondary NRE obscures the cause | One Error log preserves exception type/HRESULT/message; disconnect succeeds | The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity. The complete Windows `Core.DeviceTests` project builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner. Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head `ded289b408`, [maui-pr build 1597833](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1597833) completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran. ### Issues Fixed Fixes #38527 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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!
Description of Change
WinUI raises
CoreWebView2Initializedfor failed initialization as well as success.WebView2Proxy.OnCoreWebView2Initializedpreviously dereferencedsender.CoreWebView2unconditionally, producing a secondaryNullReferenceExceptionwhen initialization failed and the core was null.Return before subscribing to native events or applying settings when the initialization exception is non-null or the native core is missing. Log the original exception through the handler's logger when available. Successful initialization still subscribes to the same four events, using the captured non-null core. The initialization subscription remains in place so the guard does not disable a later initialization attempt.
The native callback forwards its exception into the same internal processing method exercised by two new Windows regression cases. These use a real uninitialized WebView2, with either no exception or an
InvalidOperationException, and verify normal return, a null core, and exactly one Error log preserving the supplied exception. Cleanup disconnects and closes the platform view. The seam is internal; no public API changes.This is intentionally limited to preventing the secondary NRE. It does not repair a missing runtime, add automatic recovery, or change the separate
MauiWebView.LoadHtml/ localLoadUrlasync error-handling paths.Validation
Checked-in regression coverage:
WebViewHandlerTests.Initialization.Windows.csaddsFailedCoreWebView2InitializationLogsErrorWithoutThrowing(bool hasException)with two rows. It exercises the full production callback processing method, not a copied guard or standalone predicate. It uses no process-global environment changes and does not pretend to induce a genuine missing-runtime failure.The exact unchanged tracked test file was compiled into a throwaway native harness with a minimal fixture adapter:
NullReferenceException; process exit 10Microsoft.Maui.dllThis is supplemental guard-removal mutation evidence, not a claim that the new seam exists in the original release. The prescribed verification script was blocked before source transitions by uncommitted fix-file changes; that script is not reported as passing. Source and test-method hashes were preserved across the targeted runs.
Genuine native reproduction: a separate throwaway WinUI scenario uses real WebView2 initialization and original native event arguments. A missing
WEBVIEW2_BROWSER_EXECUTABLE_FOLDERis set only inside an isolated child process, leaving the installed runtime and machine/user environment unchanged. Both original and fixed behavior were verified against repository-built MAUI assemblies.FileNotFoundException(0x80070002), null core, secondary callback NREVirtualView.Navigated(..., Success)The native extended scenario was rerun after adding the seam: success and failure controls both exit 0. Loaded DLL hashes and PDB source checksums match the tested Release artifact. The harness supplies a minimal virtual view and captures callback exceptions for assertions; this is not an uncaught full-application crash test. Native exception assertions compare type/HRESULT/message because repeated WinRT getter reads need not preserve managed object identity.
The complete Windows
Core.DeviceTestsproject builds successfully, including the new theory, and the changed files were formatted. The entire device-test suite was not run locally. An inconsistent per-control user-data-folder failure trigger was deliberately not added to the shared runner.Claude Opus 4.7 and GPT-5.5 reviewed both the original guard and the follow-up internal seam/test changes, finding no actionable issues. For head
ded289b408, maui-pr build 1597833 completed successfully: all 26 jobs succeeded, including Windows and macOS build integration tests. All published GitHub checks were successful or skipped when checked on September 15, 2026. This does not imply a separate device-test or UI-test pipeline ran.Issues Fixed
Fixes #38527