Repository navigation
fix(win32): Surface exceptions thrown while starting the app (backport #25929) - #26697
Open
mergify[bot] wants to merge 3 commits into
Open
mergify[bot] wants to merge 3 commits into
mergify[bot] wants to merge 3 commits into
Conversation
As in WinUI, the exception propagates unless a handler sets Handled. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 90f4bbe)
The event loop only logged them, and with no window it never exited (fixes #24930). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 346e1dc)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 22d9dde)
2 of 5 tasks
Contributor
Author
|
Tick the box to add this pull request to the merge queue (same as
|
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Contributor
|
The build 248842 found UI Test snapshots differences: Details
|
ajpinedam
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue: closes #24930
PR Type:
🐞 Bugfix
What changed? 🚀
On the Win32 host, an exception thrown while the app starts (from
OnLaunched, theAppconstructor or a static initializer reached from it) was swallowed. The process stayed alive with no window, and neitherApplication.UnhandledExceptionnorAppDomain.UnhandledExceptionwas raised.Cause.
Win32Host.RunLooprunsApplication.Startas an action on the Win32 message loop.Win32EventLoop.WndProccatches whatever an action throws and only logs it, which writes nothing without a configured logger. The loop exits only once every window has closed, so with no window it waits inGetMessageforever. The X11 and macOS hosts let the same exception propagate.This is the Win32 counterpart of #24308, fixed for WebAssembly in #25859. Both now follow the same pattern: the host captures the startup failure and rethrows it from
RunLoop, sohost.Run()/RunAsync()fails.Fix
Application.InvokeOnLaunched(all hosts): whenOnLaunchedthrows,Application.UnhandledExceptionis raised. As in WinUI, the exception propagates unless a handler setsHandled. No host raised this event forOnLaunchedbefore. It is a plain catch-and-rethrow, so the handler runs afterOnLaunchedhas unwound, and the original stack is kept.Win32Host.RunLoop: the startup action catches whatApplication.Startthrows, and the loop rethrows it (ExceptionDispatchInfo) after the pass that ran it.host.Run()then throws inMain, and the process terminates withAppDomain.UnhandledException. A secondary-ALC app started on an already-running loop keeps the previous log-only behavior, so one guest app failing to start can't take down the host app.Effect on WebAssembly:
InvokeOnLaunchedruns inside #25859's deferred launch, so WebAssembly now raisesApplication.UnhandledExceptionbefore faultingRunAsync. If a handler setsHandled, it no longer faults, matching WinUI and Win32.Not covered: exceptions from dispatched work after startup are still only logged (
NativeDispatcher.RunAction) on every platform. That is #19197.Validation
Unit tests: new
Given_Application_OnLaunched. It builds an app whoseOnLaunchedthrows in a secondary ALC, and callsInvokeOnLaunched.Both fail without the change and pass with it. They also pass alongside
Given_UnitTestUIThreadandGiven_AlcCacheSweep.Win32, runtime: a blank
net10.0-desktopapp onUno.Sdk 7.0.0-dev.127(Uno7.0.0-dev.2526), with this branch'sUno.UI.dllandUno.UI.Runtime.Win32.dllswapped in. Each case checked 10 s after launch:OnLaunchedApplication.UnhandledException, thenAppDomain.UnhandledException, exit0xE0434352OnLaunched, handler setsHandledApplication.UnhandledException, keeps runningAppconstructorAppDomain.UnhandledException, exit0xE0434352WebAssembly, runtime: SamplesApp published from a clean build and run in headless Edge, with temporary hooks (not committed) that throw from
OnLaunchedand log the event:Application.UnhandledException, then "App failed to initialize", andRunAsyncfaultsfail:log entriesHandledApplication.UnhandledException; nothing faultsTwo other runs failed in JavaScript before the app code ran (
window.setImmediate is not a function, and once nothing loaded). The same load flake showed up while validating #25859, so they're excluded.Compile:
Uno.UI.Runtime.Win32andUno.UIbuild with analyzers on, with no warnings in the changed files.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
This is an automatic backport of pull request #25929 done by [Mergify](https://mergify.com).