Repository navigation
[BlazorWebView] Fix dispatcher exception propagation - #37974
Conversation
<!-- 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 Updates the pinned `@microsoft/vally-cli` version used by skill validation and live soak workflows from 0.12.0 to the latest stable release, 0.14.0. Also updates direct lint command examples and makes eval-spec comments version-neutral where the described scoring behavior remains unchanged. ## Validation - Installed Vally 0.14.0 through `.github/scripts/SetupVallyRuntime.sh` - Strict-linted all 16 Vally evaluation specifications with Vally 0.14.0 Co-authored-by: PureWeen <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9e73594e-38bc-4937-80c8-cc054aa890d2
<!-- 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 Removes the `IlcTreatWarningsAsErrors=false` workaround and its TODO from the Apple NativeAOT simulator integration test. The linked tracking issue, #19397, was closed after all template trimming warnings were resolved. The dedicated `AOTTemplateTest.PublishNativeAOT` suite also maintains an empty expected-warning baseline for Apple NativeAOT builds, so the simulator run should enforce the default ILC warning policy again. ## Validation - The exact `AppleTemplateTests.RunOniOS_MauiNativeAOT` test compiled and started on Windows, but Windows could not complete the Apple ILC phase because the iOS-simulator NativeAOT runtime pack was unavailable (`MSB3030` for `System.Runtime.InteropServices.RuntimeInformation.dll`). - The Windows `AOTTemplateTest.PublishNativeAOT(... win-arm64)` proxy passed, including its assertion that the complete NativeAOT binlog warning list is empty. Apple-specific ILC/codegen and simulator execution require the macOS CI lanes and will be monitored on this draft PR. Copilot-Session: 37f90cb9-27a1-41b7-b954-95bbbcc9e81e Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 18d40d9b-be01-4868-8c88-0c50a0d0c0bf
|
🚀 Dogfood this PR with:
Or
|
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 2
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
Microsoft.Maui.sln — The solution entry uses the legacy C# project type GUID ({FAE04...}), but this is an SDK-style… |
|
Microsoft.Maui-dev.sln — The solution entry uses the legacy C# project type GUID ({FAE04...}), but this is an SDK-style… |
What changed in this PR
This PR aligns the BlazorWebView dispatcher implementations (WPF, Windows Forms, and MAUI) with the expected ASP.NET Core dispatcher contract by ensuring exceptions/cancellation propagate via the returned Task (without duplicate UI-thread rethrows) and that async work items are fully awaited. It also adds targeted regression coverage, including real STA-thread WPF/WinForms tests, and registers the new Windows unit test project for Windows Helix runs.
Changes:
- Refactored WPF and WinForms dispatchers to capture outcomes via
TaskCompletionSourceinstead of rethrowing on the UI thread, and to await async delegates fully. - Updated MAUI dispatcher to
awaitDispatchAsyncsoOperationCanceledExceptionmaps to a canceledTaskrather than a faulted one. - Added new WPF/WinForms STA dispatcher regression tests plus matching MAUI dispatcher tests, and wired the Windows unit tests into solutions + Helix.
| File | Description |
|---|---|
| src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiDispatcherTests.cs | Adds MAUI dispatcher tests for exception and cancellation propagation across all overloads. |
| src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiBlazorWebView.UnitTests.csproj | Adds Core project reference needed by new MAUI dispatcher tests. |
| src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/WpfDispatcherTests.cs | Adds STA-thread WPF dispatcher tests verifying failures don’t surface as unhandled exceptions. |
| src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/WindowsFormsDispatcherTests.cs | Adds STA-thread WinForms dispatcher tests verifying failure/cancellation behavior and no unhandled UI exceptions. |
| src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/WindowsDispatcherFixture.cs | Introduces STA-thread fixture hosting real WPF Dispatcher and WinForms message loop for tests. |
| src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/DispatcherTestHelpers.cs | Shared helper assertions for dispatcher failure/cancellation behavior across overloads. |
| src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/BlazorWebView.Windows.UnitTests.csproj | New Windows-only unit test project for WPF/WinForms dispatcher behavior. |
| src/BlazorWebView/src/Wpf/WpfDispatcher.cs | Removes UI-thread rethrow pattern; captures completion/fault/cancel via TCS and awaits async work items. |
| src/BlazorWebView/src/Wpf/Properties/AssemblyInfo.cs | Grants test assembly access to internals via InternalsVisibleTo. |
| src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs | Removes UI-thread rethrow pattern; captures completion/fault/cancel via TCS and awaits async work items. |
| src/BlazorWebView/src/WindowsForms/Properties/AssemblyInfo.cs | Grants test assembly access to internals via InternalsVisibleTo. |
| src/BlazorWebView/src/Maui/MauiDispatcher.cs | Switches to async/await to ensure cancellation becomes canceled task state (not faulted). |
| Microsoft.Maui.sln | Adds the new Windows unit test project to the main solution. |
| Microsoft.Maui-windows.slnf | Adds the new Windows unit test project to the Windows solution filter. |
| Microsoft.Maui-dev.sln | Adds the new Windows unit test project to the dev solution. |
| eng/helix.proj | Registers the new Windows unit test project for Windows Helix queues only. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 18d40d9b-be01-4868-8c88-0c50a0d0c0bf
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 2
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
src/BlazorWebView/src/Wpf/WpfDispatcher.cs — Awaiting the dispatched async work item with ConfigureAwait(false) can cause the remainder of the… |
|
src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs — Awaiting the dispatched async work item with ConfigureAwait(false) can cause the remainder of the… |
Issues resolved since last review (2)
| Severity | Finding |
|---|---|
Microsoft.Maui-dev.sln — The solution entry uses the legacy C# project type GUID ({FAE04...}), but this is an SDK-style… View resolved comment |
|
Microsoft.Maui.sln — The solution entry uses the legacy C# project type GUID ({FAE04...}), but this is an SDK-style… View resolved comment |
Suppressed comments (2)
src/BlazorWebView/src/Wpf/WpfDispatcher.cs:60
InvokeAsyncCoreawaitsworkItem()usingConfigureAwait(false)both on the dispatcher thread (CheckAccess path) and inside the dispatchedAction. That means async delegates can resume off the WPF dispatcher thread, which undermines the point of using a WPF dispatcher and can lead to cross-thread UI access for code after anawait.
Prefer await workItem() so continuations return to the WPF dispatcher synchronization context.
if (CheckAccess())
{
return await workItem().ConfigureAwait(false);
}
var completion = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
// WPF dispatches an Action, so capture the asynchronous result and all outcomes in the returned task.
Action action = async () =>
{
try
{
completion.TrySetResult(await workItem().ConfigureAwait(false));
}
src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs:76
InvokeAsyncCoreusesConfigureAwait(false)when awaitingworkItem()both on the UI thread (CheckAccess path) and inside theBeginInvokecallback. This causes async work items to resume on a thread-pool thread instead of the WinForms synchronization context, which can break thread-affine operations after anawait.
Prefer await workItem() so continuations flow back to the WinForms UI thread by default.
if (CheckAccess())
{
return await workItem().ConfigureAwait(false);
}
var completion = new TaskCompletionSource<TResult>(TaskCreationOptions.RunContinuationsAsynchronously);
// BeginInvoke accepts an Action, so capture the asynchronous result and all outcomes in the returned task.
Action action = async () =>
{
try
{
completion.TrySetResult(await workItem().ConfigureAwait(false));
}
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 18d40d9b-be01-4868-8c88-0c50a0d0c0bf
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: None
Issues resolved since last review (2)
| Severity | Finding |
|---|---|
src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs — Awaiting the dispatched async work item with ConfigureAwait(false) can cause the remainder of the… View resolved comment |
|
src/BlazorWebView/src/Wpf/WpfDispatcher.cs — Awaiting the dispatched async work item with ConfigureAwait(false) can cause the remainder of the… View resolved comment |
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiDispatcherTests.cs:36
- These tests await the dispatcher task without a timeout. If a future regression causes InvokeAsync to never complete, the test can hang until the test runner’s global timeout. Align with the Windows dispatcher tests by adding a small WaitAsync timeout around the awaited task.
This issue also appears on line 56 of the same file.
var thrown = await Assert.ThrowsAnyAsync<Exception>(() => task);
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiDispatcherTests.cs:56
- This cancellation test awaits the dispatcher task without a timeout. Adding WaitAsync helps avoid suite hangs if InvokeAsync stops completing in some failure mode.
var thrown = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 6 findings
See inline comments for details.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 2
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
src/BlazorWebView/src/Wpf/WpfDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via… |
|
src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via… |
Clarify that the intermediate fault preserves the original cancellation exception while the outer async dispatcher task completes canceled. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 18d40d9b-be01-4868-8c88-0c50a0d0c0bf
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Review tier: Lite
Findings: None
Issues resolved since last review (2)
| Severity | Finding |
|---|---|
src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via… View resolved comment |
|
src/BlazorWebView/src/Wpf/WpfDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via… View resolved comment |
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiDispatcherTests.cs:39
- These async asserts await the dispatcher task without a timeout. If a regression causes the task to never complete, this test will hang the suite instead of failing deterministically (the Windows dispatcher helpers use WaitAsync timeouts for this reason).
This issue also appears on line 68 of the same file.
var thrown = await Assert.ThrowsAnyAsync<Exception>(() => task);
src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiDispatcherTests.cs:68
- This cancellation assert awaits the task without a timeout. If the task stops completing (e.g., due to a dispatcher regression), the test will hang rather than failing with a clear timeout error.
var thrown = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
AI Review Summary
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After FixGate Result:
|
| Candidate | Alternative mechanism | Result | Tests |
|---|---|---|---|
1 (claude-opus-5) |
Transport the work item's state-machine task and Unwrap |
Blocked | Not run |
2 (gpt-5.6-sol) |
Switch the async state-machine continuation onto the UI dispatcher | Blocked | Not run |
The blocker is the mandatory EstablishBrokenBaseline.ps1 dirty-tree guard: approximately 55 pre-existing modified .github/ and eng/ files must be preserved, so the script cannot establish the baseline and does not create .github/.baseline-state.json. Both attempts obeyed the missing-allow-list rule, produced empty diffs, ran inline self-review with zero findings, left the prior gate untouched, and invoked the required restore command.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
The submitted PR has the right core direction: it removes duplicate UI-thread rethrows, preserves returned-task fault/cancellation semantics, waits for async delegates, explicitly observes discarded tasks, and adds broad dispatcher regression coverage. The expert review nevertheless identified teardown paths where the new TaskCompletionSource bridge can remain pending indefinitely and a WinForms disposal path where cancellation or failure can prevent base.Dispose(disposing).
pr-plus-reviewer is the strongest candidate because it retains the submitted mechanism and tests while adding bounded lifecycle cancellation and unconditional WinForms base cleanup. Its two focused validation commands were blocked before execution by missing candidate-local NuGet assets (NETSDK1004), so this result is unverified rather than failed. The trusted Gate is also INCONCLUSIVE; neither condition alone is treated as a regression failure, but together they preclude approval.
Candidate comparison
| Rank | Candidate | Materialized diff | Regression evidence | Assessment |
|---|---|---|---|---|
| 1 | pr-plus-reviewer |
Yes | Blocked before execution (NETSDK1004) |
Best code-level result. Preserves the PR behavior and closes the WPF/WinForms teardown completion gap; also guarantees WinForms base cleanup after manager disposal starts. |
| 2 | pr |
Yes | Trusted Gate inconclusive; author-reported focused results are not independently verified here | Sound primary fix and substantially better coverage than the base branch, but leaves pending dispatcher tasks during UI teardown and can skip WinForms base disposal. |
| 3 | try-fix-1 |
No | Not run; candidate blocked before editing | Promising task-transport/Unwrap design, but only a proposal. It supplies no diff or empirical evidence and does not independently resolve a user delegate whose UI continuation is stranded by shutdown. |
| 4 | try-fix-2 |
No | Not run; candidate blocked before editing | Promising dispatcher-switch-awaiter design, but only a proposal. It supplies no diff or empirical evidence and introduces a larger unreviewed custom-awaiter surface. |
No candidate completed the required regression tests, and no candidate has a regression-test failure. The rule that failing candidates rank below passing candidates therefore does not change this ordering.
Expert finding reconciliation
- Accepted and refined: WPF shutdown can strand
completion.Task; WinForms control teardown can do the same; WinForms manager disposal can prevent base/native cleanup. - Valid concern, not changed in the bounded patch: a throwing logger provider can fault the discarded observation task. There is no non-silent generic fallback, and swallowing provider failures would conflict with repository error-handling policy.
- Intentional compatibility tradeoff, not changed: removing
Dispatcher.UnhandledException/Application.ThreadExceptionrethrows is the purpose of the fix. Reintroducing them would recreate duplicate reporting and process-termination behavior. Fire-and-forget production paths now log faults when logging is configured. - Rejected:
HelixTargetQueueis not a typo forHelixTargetQueues; it is the Helix SDK's per-queue property. Changing the condition to inspect the full queue list would alter its semantics.
Required PR action
Apply the pr-plus-reviewer/reviewer.patch changes and rerun the two focused dispatcher test commands in a restored environment. Because the winning candidate is not the raw submitted PR, the recommendation is REQUEST CHANGES.
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: The reviewer-refined PR preserves the submitted dispatcher semantics while adding terminal cancellation during WPF/WinForms teardown and ensuring WinForms base disposal cannot be skipped after manager disposal starts. Its focused tests were blocked before execution by missing candidate-local restore assets, so the win is based on the stronger materialized implementation with explicit validation uncertainty.
Address the actionable findings in this review before merging.
kubaflo
left a comment
There was a problem hiding this comment.
Could you pleas check the ai's suggestions?
|
@kubaflo I checked every AI suggestion. Each valid finding was corrected, tested, and its thread resolved; suggestions that did not match the runtime behavior were investigated, answered with concrete test evidence, and resolved without weakening the dispatcher contract. There are now 0 unresolved AI threads, and the latest Copilot review reported no new findings. The final validation includes 48/48 real-STA WPF/WinForms tests, 66/66 MAUI dispatcher tests, focused Release fault/cancellation coverage proving canceled (not faulted) returned tasks with original exception identity, successful Windows project builds, and a passing maui-pr build 1574191. Could you please refresh and re-review the current head (fd6ab1624)? |
<!-- 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! Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.
<!-- 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 Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations. The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed `OperationCanceledException` as a fault instead of cancellation. This change: - removes the eight duplicate UI-thread rethrow paths - completes returned tasks with the original exception and preserved stack/aggregate shape - maps `OperationCanceledException` to canceled task state with its original exception and cancellation token, including `CancellationToken.None` - ensures async dispatcher overloads wait for the delegated task - explicitly observes intentional fire-and-forget dispatcher calls, ignores expected cancellation, and logs faults - adds real STA-thread WPF and Windows Forms regression tests for all overloads, both marshaled and `CheckAccess() == true` paths, and async UI-thread affinity - adds matching MAUI dispatcher tests and Windows Helix registration The behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art. ## Testing - `BlazorWebView.Windows.UnitTests`: 48 passed - `MauiBlazorWebView.UnitTests`: 66 passed - WPF Release target: build passed with 0 warnings/errors - Windows Forms Release target: build passed with 0 warnings/errors - MAUI Windows Release target: build passed with 0 warnings/errors The Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because `CoreWebView2` never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.



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
Fixes exception and cancellation propagation for the WPF, Windows Forms, and MAUI BlazorWebView dispatcher implementations.
The WPF and Windows Forms dispatchers previously faulted the returned task and then separately rethrew the same exception on the UI thread. That could report an observed exception twice or terminate the process. WPF async delegates could also complete their dispatcher task before the inner task completed, while MAUI exposed
OperationCanceledExceptionas a fault instead of cancellation.This change:
OperationCanceledExceptionto canceled task state with its original exception and cancellation token, includingCancellationToken.NoneCheckAccess() == truepaths, and async UI-thread affinityThe behavior now matches the ASP.NET Core dispatcher contract and current BlazorWebView dispatcher prior art.
Testing
BlazorWebView.Windows.UnitTests: 48 passedMauiBlazorWebView.UnitTests: 66 passedThe Windows BlazorWebView device-test app built successfully. On this ARM64 host, 16 WebView-dependent tests timed out because
CoreWebView2never became available; 3 passed and 4 were skipped. All 16 failures had the same host prerequisite timeout and were unrelated to dispatcher behavior.