Skip to content

fix(win32): Surface exceptions thrown while starting the app (backport #25929) - #26697

Open
mergify[bot] wants to merge 3 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25929
Open

mergify[bot] wants to merge 3 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25929

Conversation

@mergify

@mergify mergify Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24930

PR Type:

🐞 Bugfix

What changed? 🚀

On the Win32 host, an exception thrown while the app starts (from OnLaunched, the App constructor or a static initializer reached from it) was swallowed. The process stayed alive with no window, and neither Application.UnhandledException nor AppDomain.UnhandledException was raised.

Cause. Win32Host.RunLoop runs Application.Start as an action on the Win32 message loop. Win32EventLoop.WndProc catches 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 in GetMessage forever. 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, so host.Run()/RunAsync() fails.

Fix

  1. Application.InvokeOnLaunched (all hosts): when OnLaunched throws, Application.UnhandledException is raised. As in WinUI, the exception propagates unless a handler sets Handled. No host raised this event for OnLaunched before. It is a plain catch-and-rethrow, so the handler runs after OnLaunched has unwound, and the original stack is kept.
  2. Win32Host.RunLoop: the startup action catches what Application.Start throws, and the loop rethrows it (ExceptionDispatchInfo) after the pass that ran it. host.Run() then throws in Main, and the process terminates with AppDomain.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: InvokeOnLaunched runs inside #25859's deferred launch, so WebAssembly now raises Application.UnhandledException before faulting RunAsync. If a handler sets Handled, 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 whose OnLaunched throws in a secondary ALC, and calls InvokeOnLaunched.

  • Unhandled: the event reports the exception, then the exception propagates.
  • Handled: no exception propagates, and the app counts as launched.

Both fail without the change and pass with it. They also pass alongside Given_UnitTestUIThread and Given_AlcCacheSweep.

Win32, runtime: a blank net10.0-desktop app on Uno.Sdk 7.0.0-dev.127 (Uno 7.0.0-dev.2526), with this branch's Uno.UI.dll and Uno.UI.Runtime.Win32.dll swapped in. Each case checked 10 s after launch:

Throw site Before After
Nothing (control) window shown window shown
OnLaunched alive, no window, no events Application.UnhandledException, then AppDomain.UnhandledException, exit 0xE0434352
OnLaunched, handler sets Handled alive, no window, no events Application.UnhandledException, keeps running
App constructor alive, no window, no events AppDomain.UnhandledException, exit 0xE0434352

WebAssembly, runtime: SamplesApp published from a clean build and run in headless Edge, with temporary hooks (not committed) that throw from OnLaunched and log the event:

Case Result
No throw (control) launches
Throw, no logger (2 runs) Application.UnhandledException, then "App failed to initialize", and RunAsync faults
Throw, logger configured (2 runs) same as above, plus the fail: log entries
Throw, handler sets Handled Application.UnhandledException; nothing faults

Two 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.Win32 and Uno.UI build with analyzers on, with no warnings in the changed files.

PR Checklist ✅

🤖 Generated with Claude Code


This is an automatic backport of pull request #25929 done by [Mergify](https://mergify.com).

ramezgerges and others added 3 commits November 24, 2026 16:12
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)
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 24, 2026
@mergify

mergify Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248842 found UI Test snapshots differences: skia-linux-screenshots: 236, skia-windows-screenshots: 308

Details
  • skia-linux-screenshots: 236 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • Basics.png-dark
    • Basics.png
    • Buttons.png-dark
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • AnimatedBackVisualSourceSamplePage.png-dark
  • skia-windows-screenshots: 308 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CenteredGridinGridwithtwofixedsizechildren.png-dark
    • CenteredGridinGridwithtwofixedsizechildren.png
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • BenchmarkDotNet.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • CalendarView_Theming.png-dark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants