Describe the bug
When App.xaml (with its code-behind) lives in a project subfolder rather than the project root, the app builds without errors, the App constructor completes (InitializeComponent() returns, _contentLoaded is true), but Application.OnLaunched is never invoked. The process exits cleanly with no exception, first-chance or otherwise. Moving App.xaml and App.xaml.cs to the project root, with nothing else changed, fixes it. MainWindow.xaml in a subfolder works fine in the same project.
Why is this important?
I wanted to group source files into folders (App/, UI/, Apply/, and so on) to keep the project root small, which is ordinary project hygiene for an app that's growing. Nothing in the docs or the build says App.xaml has to sit at the root, and the build accepts it without a warning.
The failure is the problem. There is no build error, no exception and no crash dialog. The app starts, constructs App, and then exits without ever calling OnLaunched. With no exception thrown, first-chance or otherwise, the only way I found the cause was by stepping into Application.Start in the debugger, comparing the generated App.g.i.cs against a known-good build, and bisecting against an earlier revision. That took a long time for what turned out to be a folder location.
For an end-user of an app the impact is worse: an app that exits silently on launch, with nothing logged, is close to undiagnosable.
This is the root issue and not an XY problem. I'm not trying to work around OnLaunched. I'm trying to keep App.xaml in a subfolder, and I expected either that to work or the build to tell me it doesn't. A build-time diagnostic would be enough for me.
Steps to reproduce the bug
- Unpackaged WinUI 3 C# app (WindowsPackageType None, WindowsAppSDKSelfContained true, Windows App SDK 2.5.1 preview).
- Move App.xaml and App.xaml.cs into a folder, e.g. App. Keep x:Class and namespaces unchanged.3.
Build, run. Breakpoint on OnLaunched: never hit.
Actual behavior
Observed, from the generated code. With App.xaml at the root, App.g.i.cs contains new Uri("ms-appx:///App.xaml") and Application.LoadComponent(this, resourceLocator), plus three #if DEBUG hooks. With it in App, the generated InitializeComponent() uses new Uri("ms-appx:///App/App.xaml") and LoadComponent(this, resourceLocator, ComponentResourceLocation.Application), and the DEBUG hooks are absent. The compiled output is App\App.xbf. The debugger shows Application.Resources throwing a COMException after construction.
Not established: why the generator emits a different InitializeComponent() shape for a non-root App.xaml, or whether this is specific to unpackaged or self-contained mode. Only App.xaml was moved this way; I haven't tested it in a packaged app.
Expected behavior
OnLaunched fires, as with App.xaml at the root.
Screenshots
No response
NuGet package version
Version info: Microsoft.WindowsAppSDK 2.5.1, .NET 11 preview, net11.0-windows10.0.26100.0, XAML compiler 3.0.0.2609, x64 Debug.
Windows version
Windows 11 (26H1): Build 28000
Additional context
What I ruled out
- Stale build output: I deleted
__Output and rebuilt; same behaviour.
- The config and persistence code:
OnLaunched is never reached, so none of the app's own startup logic runs.
- A first-chance exception: with CLR exceptions enabled, nothing throws. Stepping past
Application.Start's callback returns 0 and the process exits.
- My own code: an earlier revision of the same project, with
App.xaml at the root, builds and runs on the same machine.
Where it stops
The Started lifecycle callback (raised from OnLaunched) never arrives; only Starting does. DispatcherShutdownMode is OnLastWindowClose and no window exists yet.
Contrast
MainWindow.xaml in a subfolder (UI\MainWindow.xaml) works in the same project, compiled to UI\MainWindow.xbf with ms-appx:///UI/MainWindow.xaml. Only App.xaml fails when moved.
Generated code difference (from App.g.i.cs)
App.xaml at the root: LoadComponent(this, new Uri("ms-appx:///App.xaml")), with DEBUG hooks for binding-failed, resource-reference-failed and UnhandledException.
App.xaml in a subfolder: LoadComponent(this, new Uri("ms-appx:///App/App.xaml"), ComponentResourceLocation.Application), no DEBUG hooks.
Environment
WindowsPackageType=None
WindowsAppSDKSelfContained=true
UseWinUI=true
DISABLE_XAML_GENERATED_MAIN (custom Main)
LangVersion=preview
- x64, custom solution-wide output folders
Workaround
Keep App.xaml and App.xaml.cs in the project root.
Describe the bug
When App.xaml (with its code-behind) lives in a project subfolder rather than the project root, the app builds without errors, the App constructor completes (InitializeComponent() returns, _contentLoaded is true), but Application.OnLaunched is never invoked. The process exits cleanly with no exception, first-chance or otherwise. Moving App.xaml and App.xaml.cs to the project root, with nothing else changed, fixes it. MainWindow.xaml in a subfolder works fine in the same project.
Why is this important?
I wanted to group source files into folders (App/, UI/, Apply/, and so on) to keep the project root small, which is ordinary project hygiene for an app that's growing. Nothing in the docs or the build says App.xaml has to sit at the root, and the build accepts it without a warning.
The failure is the problem. There is no build error, no exception and no crash dialog. The app starts, constructs App, and then exits without ever calling OnLaunched. With no exception thrown, first-chance or otherwise, the only way I found the cause was by stepping into Application.Start in the debugger, comparing the generated App.g.i.cs against a known-good build, and bisecting against an earlier revision. That took a long time for what turned out to be a folder location.
For an end-user of an app the impact is worse: an app that exits silently on launch, with nothing logged, is close to undiagnosable.
This is the root issue and not an XY problem. I'm not trying to work around OnLaunched. I'm trying to keep App.xaml in a subfolder, and I expected either that to work or the build to tell me it doesn't. A build-time diagnostic would be enough for me.
Steps to reproduce the bug
Build, run. Breakpoint on OnLaunched: never hit.
Actual behavior
Observed, from the generated code. With App.xaml at the root, App.g.i.cs contains new Uri("ms-appx:///App.xaml") and Application.LoadComponent(this, resourceLocator), plus three #if DEBUG hooks. With it in App, the generated InitializeComponent() uses new Uri("ms-appx:///App/App.xaml") and LoadComponent(this, resourceLocator, ComponentResourceLocation.Application), and the DEBUG hooks are absent. The compiled output is App\App.xbf. The debugger shows Application.Resources throwing a COMException after construction.
Not established: why the generator emits a different InitializeComponent() shape for a non-root App.xaml, or whether this is specific to unpackaged or self-contained mode. Only App.xaml was moved this way; I haven't tested it in a packaged app.
Expected behavior
OnLaunched fires, as with App.xaml at the root.
Screenshots
No response
NuGet package version
Version info: Microsoft.WindowsAppSDK 2.5.1, .NET 11 preview, net11.0-windows10.0.26100.0, XAML compiler 3.0.0.2609, x64 Debug.
Windows version
Windows 11 (26H1): Build 28000
Additional context
What I ruled out
__Outputand rebuilt; same behaviour.OnLaunchedis never reached, so none of the app's own startup logic runs.Application.Start's callback returns 0 and the process exits.App.xamlat the root, builds and runs on the same machine.Where it stops
The
Startedlifecycle callback (raised fromOnLaunched) never arrives; onlyStartingdoes.DispatcherShutdownModeisOnLastWindowCloseand no window exists yet.Contrast
MainWindow.xamlin a subfolder (UI\MainWindow.xaml) works in the same project, compiled toUI\MainWindow.xbfwithms-appx:///UI/MainWindow.xaml. OnlyApp.xamlfails when moved.Generated code difference (from
App.g.i.cs)App.xamlat the root:LoadComponent(this, new Uri("ms-appx:///App.xaml")), withDEBUGhooks for binding-failed, resource-reference-failed andUnhandledException.App.xamlin a subfolder:LoadComponent(this, new Uri("ms-appx:///App/App.xaml"), ComponentResourceLocation.Application), noDEBUGhooks.Environment
WindowsPackageType=NoneWindowsAppSDKSelfContained=trueUseWinUI=trueDISABLE_XAML_GENERATED_MAIN(customMain)LangVersion=previewWorkaround
Keep
App.xamlandApp.xaml.csin the project root.