Skip to content

[BlazorWebView] Fix dispatcher exception propagation - #37974

Merged
kubaflo merged 12 commits into
inflight/currentfrom
jfversluis-resolve-dispatcher-rethrow-todos
Aug 30, 2026
Merged

kubaflo merged 12 commits into
inflight/currentfrom
jfversluis-resolve-dispatcher-rethrow-todos

Conversation

@jfversluis

@jfversluis jfversluis commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

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

PureWeen and others added 3 commits August 27, 2026 23:46
<!-- 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
Copilot AI lite review requested due to automatic review settings August 28, 2026 19:30
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37974

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37974"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

Review tier: Lite
Findings: 2 Low severity

New issues introduced by this change (2)
Severity Finding
Low severity Microsoft.Maui.sln — The solution entry uses the legacy C# project type GUID ({FAE04...}), but this is an SDK-style…
Low severity 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 TaskCompletionSource instead of rethrowing on the UI thread, and to await async delegates fully.
  • Updated MAUI dispatcher to await DispatchAsync so OperationCanceledException maps to a canceled Task rather 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.

Comment thread Microsoft.Maui.sln Resolved
Comment thread Microsoft.Maui-dev.sln Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 18d40d9b-be01-4868-8c88-0c50a0d0c0bf
Copilot AI review requested due to automatic review settings August 28, 2026 20:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

Review tier: Lite
Findings: 2 High severity

New issues introduced by this change (2)
Severity Finding
High severity src/​BlazorWebView/​src/​Wpf/​WpfDispatcher.cs — Awaiting the dispatched async work item with ConfigureAwait(false) can cause the remainder of the…
High severity 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
Low severity Microsoft.Maui-dev.sln — The solution entry uses the legacy C# project type GUID ({FAE04...}), but this is an SDK-style… View resolved comment
Low severity 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

  • InvokeAsyncCore awaits workItem() using ConfigureAwait(false) both on the dispatcher thread (CheckAccess path) and inside the dispatched Action. 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 an await.

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

  • InvokeAsyncCore uses ConfigureAwait(false) when awaiting workItem() both on the UI thread (CheckAccess path) and inside the BeginInvoke callback. 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 an await.

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
Copilot AI review requested due to automatic review settings August 28, 2026 20:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

Review tier: Lite
Findings: None

Issues resolved since last review (2)
Severity Finding
High severity src/​BlazorWebView/​src/​WindowsForms/​WindowsFormsDispatcher.cs — Awaiting the dispatched async work item with ConfigureAwait(false) can cause the remainder of the… View resolved comment
High severity 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);

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Aug 28, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 6 findings

See inline comments for details.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates labels Aug 29, 2026
@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Aug 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 2 Medium severity

New issues introduced by this change (2)
Severity Finding
Medium severity src/​BlazorWebView/​src/​Wpf/​WpfDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via…
Medium severity src/​BlazorWebView/​src/​WindowsForms/​WindowsFormsDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via…

Copilot AI review requested due to automatic review settings August 30, 2026 14:51
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Review tier: Lite
Findings: None

Issues resolved since last review (2)
Severity Finding
Medium severity src/​BlazorWebView/​src/​WindowsForms/​WindowsFormsDispatcher.cs — OperationCanceledException thrown by a dispatched work item is currently captured via… View resolved comment
Medium severity 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);

@MauiBot

MauiBot commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

AI Review Summary

@jfversluis — new AI review results are available based on commit 6c41d1f.

Gate Inconclusive Confidence Medium Platform Windows


🗂️ Review Sessions — click to expand

[!WARNING]
This run reviewed commit 6c41d1f, but the PR advanced to ffd6ab1 while it was running. These results are informational; re-run /review for the current head.


🚦 Gate — Test Before & After Fix

Gate Result: ⚠️ INCONCLUSIVE

Platform: WINDOWS

⚠️ The gate could not conclusively verify the fix on this run: it hit an environment/infrastructure error while building or running the tests (exit code 3 = INCONCLUSIVE), so no reliable pass/fail was produced. This is not a problem with your PR — comment /review to retry on a fresh agent. The diagnostics below show what was captured before it stopped.

Exit code: 3

Artifacts written before exit:

  • verification-log.txt (7.3 KB)
Gate output log (last 60 lines)
[2026-08-30 14:33:59]   ✓ src/BlazorWebView/src/Maui/MauiDispatcher.cs (exists at merge-base - will revert)
[2026-08-30 14:33:59]   ✓ src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs (exists at merge-base - will revert)
[2026-08-30 14:34:00]   ○ src/BlazorWebView/src/SharedSource/WebViewTaskExtensions.cs (new file - skipping revert)
[2026-08-30 14:34:00]   ✓ src/BlazorWebView/src/WindowsForms/BlazorWebView.cs (exists at merge-base - will revert)
[2026-08-30 14:34:00]   ○ src/BlazorWebView/src/WindowsForms/Properties/AssemblyInfo.cs (new file - skipping revert)
[2026-08-30 14:34:00]   ✓ src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs (exists at merge-base - will revert)
[2026-08-30 14:34:00]   ✓ src/BlazorWebView/src/Wpf/BlazorWebView.cs (exists at merge-base - will revert)
[2026-08-30 14:34:00]   ✓ src/BlazorWebView/src/Wpf/Properties/AssemblyInfo.cs (exists at merge-base - will revert)
[2026-08-30 14:34:00]   ✓ src/BlazorWebView/src/Wpf/WpfDispatcher.cs (exists at merge-base - will revert)
[2026-08-30 14:34:00] 
[2026-08-30 14:34:00] Checking for uncommitted changes on revertable files...
[2026-08-30 14:34:00]   ✓ All revertable fix files are committed
[2026-08-30 14:34:00] 
[2026-08-30 14:34:00] ==========================================
[2026-08-30 14:34:00] STEP 1: Reverting fix files to merge-base (abdfbef0)
[2026-08-30 14:34:00] ==========================================
[2026-08-30 14:34:00]   Reverting: Microsoft.Maui-dev.sln
[2026-08-30 14:34:00]   Reverting: Microsoft.Maui-windows.slnf
[2026-08-30 14:34:00]   Reverting: Microsoft.Maui.sln
[2026-08-30 14:34:00]   Reverting: eng/helix.proj
[2026-08-30 14:34:00]   Reverting: src/BlazorWebView/src/Maui/BlazorWebViewHandler.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/Maui/MauiDispatcher.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/WindowsForms/BlazorWebView.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/Wpf/BlazorWebView.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/Wpf/Properties/AssemblyInfo.cs
[2026-08-30 14:34:01]   Reverting: src/BlazorWebView/src/Wpf/WpfDispatcher.cs
[2026-08-30 14:34:01]   ✓ 12 fix file(s) reverted to merge-base state
[2026-08-30 14:34:01] 
[2026-08-30 14:34:01]   Removing 2 PR-added file(s) so the baseline matches the pre-fix tree:
[2026-08-30 14:34:01]     Removing (new in PR): src/BlazorWebView/src/SharedSource/WebViewTaskExtensions.cs
[2026-08-30 14:34:01]     Removing (new in PR): src/BlazorWebView/src/WindowsForms/Properties/AssemblyInfo.cs
[2026-08-30 14:34:01]   ✓ 2 PR-added file(s) removed for the baseline
╔═══════════════════════════════════════════════════════════╗
║  STEP 2: Running tests WITHOUT fix (expect FAIL)          ║
╚═══════════════════════════════════════════════════════════╝
[2026-08-30 14:34:01] 
[2026-08-30 14:34:01] STEP 2: Running tests WITHOUT fix (should FAIL)
##[group]🔴 WITHOUT FIX 1/3: 🧪 MauiDispatcherTests (filter: MauiDispatcherTests)
❌ Could not determine unit test project to run.
   Detected project: 
   Path: 
[2026-08-30 14:34:01] 
[2026-08-30 14:34:01] ⚠️  Verification ended inside the baseline mutation window — restoring the with-fix tree from HEAD
[2026-08-30 14:34:01]   Restoring: Microsoft.Maui-dev.sln
[2026-08-30 14:34:01]   Restoring: Microsoft.Maui-windows.slnf
[2026-08-30 14:34:01]   Restoring: Microsoft.Maui.sln
[2026-08-30 14:34:01]   Restoring: eng/helix.proj
[2026-08-30 14:34:01]   Restoring: src/BlazorWebView/src/Maui/BlazorWebViewHandler.cs
[2026-08-30 14:34:01]   Restoring: src/BlazorWebView/src/Maui/MauiDispatcher.cs
[2026-08-30 14:34:01]   Restoring: src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs
[2026-08-30 14:34:01]   Restoring: src/BlazorWebView/src/WindowsForms/BlazorWebView.cs
[2026-08-30 14:34:01]   Restoring: src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs
[2026-08-30 14:34:01]   Restoring: src/BlazorWebView/src/Wpf/BlazorWebView.cs
[2026-08-30 14:34:02]   Restoring: src/BlazorWebView/src/Wpf/Properties/AssemblyInfo.cs
[2026-08-30 14:34:02]   Restoring: src/BlazorWebView/src/Wpf/WpfDispatcher.cs
[2026-08-30 14:34:02]   Restoring (new in PR): src/BlazorWebView/src/SharedSource/WebViewTaskExtensions.cs
[2026-08-30 14:34:02]   Restoring (new in PR): src/BlazorWebView/src/WindowsForms/Properties/AssemblyInfo.cs
[2026-08-30 14:34:02]   ✓ Worktree/index restored to HEAD

📋 Pre-Flight — Context & Validation

PR #37974 Pre-Flight

Pull request

  • Title: [BlazorWebView] Fix dispatcher exception propagation
  • State: Open, not draft
  • Author: jfversluis
  • Base/head: main <- jfversluis-resolve-dispatcher-rethrow-todos
  • Materialized review commit: 3e14cb8bc42dda94477040faad2d288c8077fe19
  • Remote head: 6c41d1fde4fe6ddddb36f7710389de8b8b46b05b
  • Scope: 21 files, +963/-217
  • Linked issue: None identified in the PR metadata.

Problem

The WPF and Windows Forms BlazorWebView dispatchers both faulted the task returned to an awaiting caller and separately rethrew the same exception on the UI thread. This could report a failure twice or terminate the process. The WPF Func<Task> path could also complete before the delegated task completed. MAUI's pass-through dispatcher exposed OperationCanceledException as a fault rather than a canceled returned task.

The required contract is:

  1. Every dispatcher overload completes only after its work item completes.
  2. Ordinary exceptions fault only the returned task, preserve the original exception/aggregate shape and stack, and are not separately rethrown on the UI thread.
  3. OperationCanceledException, including one carrying CancellationToken.None, produces a canceled returned task while preserving the original exception and token.
  4. Async delegates start and resume with the platform UI-thread affinity expected by WPF and Windows Forms.
  5. Intentional fire-and-forget callers explicitly observe faults, ignore genuine task cancellation, and log unexpected failures.

Existing PR approach

  • WPF and Windows Forms route all four overloads through one generic InvokeAsyncCore<TResult>.
  • The marshaled path posts an async void Action, bridges its result through a TaskCompletionSource<TResult>, awaits the native dispatch operation, then awaits the completion task.
  • The bridge currently records every thrown exception with TrySetException; the outer async method then normalizes an escaped OperationCanceledException to cancellation.
  • MAUI wraps each IDispatcher.DispatchAsync task in an async method so an OperationCanceledException stored as a fault is normalized to cancellation.
  • WebViewTaskExtensions.ObserveExceptionsAsync observes deliberate fire-and-forget calls, suppresses only an actually canceled task, and logs other faults.
  • New real-STA WPF/Windows Forms tests cover all overloads, marshaled and CheckAccess() == true paths, exception identity, cancellation identity/token/state, and async UI affinity. Matching MAUI tests cover propagation and observation behavior.

Direct diff inspection

The production changes are concentrated in:

  • src/BlazorWebView/src/Maui/MauiDispatcher.cs
  • src/BlazorWebView/src/Wpf/WpfDispatcher.cs
  • src/BlazorWebView/src/WindowsForms/WindowsFormsDispatcher.cs
  • src/BlazorWebView/src/SharedSource/WebViewTaskExtensions.cs
  • five fire-and-forget call sites in the MAUI, WPF, Windows Forms, and shared WebView2 implementations

The remaining changes add the Windows unit-test project, test infrastructure, solution/Helix registration, internals visibility, and MAUI dispatcher tests.

Recent review iterations already rejected or corrected these approaches:

  • Restoring dispatcher-level UI-thread rethrows: duplicates awaited failures and does not reliably cover discarded tasks.
  • Treating the bridge's ConfigureAwait(false) as moving the user delegate off the UI thread: real STA tests show the delegate captures the UI synchronization context when invoked.
  • Token-only TrySetCanceled: discarded the original cancellation exception and differed from the fast path.
  • A parent-namespace FireAndForget extension: shadowed the existing MAUI helper.
  • Global WinForms unhandled-exception mode and fragile fixture cleanup/startup bounds: corrected in the current PR.

The latest two automated comments claim TrySetException(OperationCanceledException) leaves the final task faulted. The current implementation deliberately awaits that intermediate task in an outer async method, whose async method builder classifies the escaping OperationCanceledException as cancellation; the new tests are intended to pin this behavior.

Allowed validation

The prior gate detected exactly three focused unit-test classes. Attempts must not run the gate again or run any broader suite.

Primary test

dotnet test src/BlazorWebView/tests/MauiBlazorWebView.UnitTests/MauiBlazorWebView.UnitTests.csproj --no-restore --filter "FullyQualifiedName~MauiDispatcherTests"

Mandatory regression tests

dotnet test src/BlazorWebView/tests/BlazorWebView.Windows.UnitTests/BlazorWebView.Windows.UnitTests.csproj --no-restore --filter "FullyQualifiedName~WindowsFormsDispatcherTests|FullyQualifiedName~WpfDispatcherTests"

Each candidate may run this pair once and, after at most one focused correction, once more.

Gate and workspace constraints

The already-completed gate is INCONCLUSIVE, not a fix failure: its detector found the three classes but produced an empty project path before test execution. Do not rerun the gate and do not create or overwrite gate/content.md.

The checkout also contains substantial pre-existing changes under .github/ and eng/ that are unrelated to this PR. Attempts must preserve them. Cleanup is exclusively:

pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore

The PR adds production files. If .github/.baseline-state.json reports a non-empty NewFiles array, the try-fix skill requires the attempt to record Blocked before editing rather than bypassing its restoration boundary.


🔬 Code Review — Deep Analysis

Expert PR Evaluation — PR #37974

Verdict: NEEDS_CHANGES

Confidence: medium on the code findings; low on overall merge safety because the trusted Gate is inconclusive.

Independent assessment

The submitted change removes the WPF and Windows Forms dispatchers' second UI-thread rethrow, makes all dispatcher overloads await the delegated operation, normalizes OperationCanceledException into canceled returned tasks, and adds explicit observation for intentionally discarded tasks. The central contract is sound and the real-STA tests cover exception identity, aggregate shape, cancellation identity/token, fast and marshaled paths, and UI-thread affinity.

The implementation is not ready as submitted because the dispatcher bridge has teardown completion gaps that are not exercised by the new tests, and the WinForms disposal path can skip native/base cleanup without diagnostics.

Actionable findings

  1. Moderate — WPF marshaled async calls have no terminal path when dispatcher shutdown strands the work item. WpfDispatcher.InvokeAsyncCore completes its TCS only inside the posted async void action. A work item that suspends and whose continuation cannot run after dispatcher shutdown leaves the returned task pending indefinitely.
  2. Moderate — WinForms has the equivalent teardown completion gap. A destroyed control handle or exited message loop after the posted action reaches its first await can leave completion.Task pending indefinitely.
  3. Moderate — WinForms disposal can bypass base.Dispose(disposing). The base call is after _webviewManager.DisposeAsync() inside the dispatched delegate. Cancellation or failure prevents base/native cleanup; cancellation is then intentionally ignored by ObserveExceptionsAsync.
  4. Moderate — the observation helper can itself fault if logging throws. All production call sites discard the helper task. This is a real secondary-fault path, although changing it requires an explicit policy because silently swallowing logger-provider exceptions is also undesirable.
  5. Discussion — removing UI-thread rethrow changes diagnostics for hosts without a configured logger. This is substantially the intended behavior change and reintroducing the rethrow would recreate the original defect. The description should retain the explicit behavior statement; a release note or other documented diagnostics policy is preferable to restoring the old mechanism.

Rejected expert finding

The raw expert output flags $(HelixTargetQueue.StartsWith('Windows')) as an undefined-property error. That finding is not actionable: HelixTargetQueue is an SDK-provided per-queue property, distinct from the configured HelixTargetQueues list. The same condition form is used by current Microsoft.DotNet.Helix.Sdk consumers (for example, dotnet/efcore and dotnet/aspnetcore). Replacing it with a list-wide HelixTargetQueues.Contains(...) condition would incorrectly change per-queue evaluation semantics.

Prior-review reconciliation

Earlier solution-project GUID findings were fixed in the submitted diff. Earlier claims that ConfigureAwait(false) moves the user delegate's own continuation off the UI thread are contradicted by the delegate invocation semantics and the real-STA affinity tests: the user delegate captures the UI synchronization context before the bridge awaits its returned task. Earlier claims that TrySetException(OperationCanceledException) necessarily leaves the final public task faulted overlook the outer async-method normalization and are covered by identity/token/state tests.

CI and validation evidence

The trusted Gate is INCONCLUSIVE because its test-project detection/build path failed before the focused tests ran. This is not evidence that the fix failed, but it prevents approval. Current remote checks are not a substitute for validation of the materialized review commit.

Refinement scope

A single consolidated pr-plus-reviewer candidate should address the lifecycle-safe completion/cleanup issues without restoring duplicate UI-thread rethrows. The logging-policy and no-provider diagnostics concerns should not be changed speculatively in this bounded refinement.

External Output Contract

Not applicable. The submitted functional code does not classify external tool output.


🛠️ Try-Fix — Analysis & Comparison

PR #37974 — Bounded Try-Fix Aggregate

Pre-flight: ../pre-flight/content.md

Candidate 1 — Transport and unwrap the work item's task

  • Model: claude-opus-5
  • Result: Blocked
  • Code/test status: No candidate diff was applied and no tests were run.
  • Self-review: 0 findings
  • Detailed narrative: ../try-fix-1/content.md
  • Attempt artifacts: attempt-1/

The proposed mechanism avoids the PR's async void/TaskCompletionSource bridge. Each work item would execute through its own guarded async state machine; WPF, Windows Forms, and MAUI would transport the resulting nested task through the native dispatch primitive and return Unwrap(). This is intended to preserve completion, fault, cancellation, exception identity, and token semantics without catching and reconstructing the outcome.

The attempt could not establish the mandatory broken baseline. EstablishBrokenBaseline.ps1 rejected approximately 55 pre-existing modified .github/ and eng/ files as a dirty working directory, did not create .github/.baseline-state.json, and therefore supplied no RevertedFiles modification allow-list. The skill required the attempt to stop before editing. The exact restore command ran and correctly reported that there was no baseline state to restore; all unrelated changes remained intact.

Candidate 2

  • Model: gpt-5.6-sol
  • Result: Blocked
  • Code/test status: No candidate diff was applied and no tests were run.
  • Self-review: 0 findings
  • Detailed narrative: ../try-fix-2/content.md
  • Attempt artifacts: attempt-2/

The distinct proposal uses a dispatcher-switch awaiter: it would move the compiler-generated async state-machine continuation onto the UI thread and then execute the work item directly. Unlike Candidate 1, it would not transport a nested task through a dispatcher or call Unwrap; unlike the PR, it would not post an async void action or reconstruct outcomes with a TaskCompletionSource.

This attempt independently ran the mandatory baseline step and hit the same dirty-worktree guard before a modification allow-list could be created. It therefore stopped without editing or testing. The exact restore command ran and correctly reported that no baseline state existed.

Aggregate result

Two candidates were generated, satisfying the hard cap. Both are Blocked by the shared baseline precondition, not failed implementations. No empirical comparison with the PR is possible from this STEP 5a run:

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.ThreadException rethrows 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: HelixTargetQueue is not a typo for HelixTargetQueues; 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.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Aug 30, 2026

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you pleas check the ai's suggestions?

@jfversluis

Copy link
Copy Markdown
Member Author

@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)?

@kubaflo
kubaflo changed the base branch from main to inflight/current August 30, 2026 20:37
@kubaflo
kubaflo merged commit 24194b4 into inflight/current Aug 30, 2026
34 checks passed
@kubaflo
kubaflo deleted the jfversluis-resolve-dispatcher-rethrow-todos branch August 30, 2026 20:38
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Aug 30, 2026
kubaflo pushed a commit that referenced this pull request Sep 2, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 3, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 11, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 15, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 18, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 21, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
<!-- 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.
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
<!-- 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.
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 30, 2026
@github-actions github-actions Bot modified the milestones: .NET 10 SR11, .NET 10 SR12 Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-blazor Blazor Hybrid / Desktop, BlazorWebView platform/windows s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants