microsoft-ui-xaml: WinUI 3 - Blank App, Packaged (WinUI 3 in Desktop) C# project template crashes in Release configuration

Describe the bug

The app created by Blank App, Packaged (WinUI 3 in Desktop) C# project template crashes in Release configuration with exception on App.g.i.cs Line 32:

global::Microsoft.UI.Xaml.Application.Start((p) => {
    var context = new global::Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(global::Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
    global::System.Threading.SynchronizationContext.SetSynchronizationContext(context);
    new App();
});

The exceptions:

Unhandled exception at 0x00007FFB31F75175 (Microsoft.ui.xaml.dll) in App1.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x000001B067EF58C0, 0x0000000000000002).
Unhandled exception at 0x00007FFB994F4470 (combase.dll) in App1.exe: 0xC0000602:  A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately.
Unhandled exception at 0x00007FFB31F75175 (Microsoft.ui.xaml.dll) in App1.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x000001B0031031D0, 0x0000000000000002).
Unhandled exception at 0x00007FFB994F4470 (combase.dll) in App1.exe: 0xC0000602:  A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately.

And in Event Viewer there is a crash event:

Faulting application name: App1.exe, version: 1.0.0.0, time stamp: 0x65f90000
Faulting module name: Microsoft.ui.xaml.dll, version: 3.1.5.0, time stamp: 0x5c2afe3b
Exception code: 0xc000027b
Fault offset: 0x0000000000405175
Faulting process id: 0x20278
Faulting application start time: 0x1DAAF3D091E67FA
Faulting application path: E:\Shirasagi\CSharp\App1\App1\bin\x64\Release\net8.0-windows10.0.19041.0\win-x64\AppX\App1.exe
Faulting module path: C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.5_5001.119.156.0_x64__8wekyb3d8bbwe\Microsoft.ui.xaml.dll
Report Id: 945b6cf3-6710-47f2-aa22-e8377a178e2e
Faulting package full name: b064c45c-ec11-40e2-b3f2-7d0ca5daf8e5_1.0.0.0_x64__kkjvz6qjy8mej
Faulting package-relative application ID: App

Steps to reproduce the bug

  1. Create a new project using the “Blank App, Packaged (WinUI 3 in Desktop)” C# project template. Both Visual Studio 17.10 and 17.11 Preview 1 are able to reproduce the bug.
  2. Switch the Solution Configuration to “Release”.
  3. In the debug properties, check the “Enable native code debugging” option so we can see the exception.
  4. Run “App1(Packaged)” with debuging, and the app crashes.
  5. If you switch the configuration back to Debug, the app runs fine.

Expected behavior

The app should run out-of-the-box in both Release and Debug configurations.

Screenshots

屏幕截图 2024-05-26 152015

NuGet package version

WinUI 3 - Windows App SDK 1.5.3: 1.5.240428000

Windows version

Windows Insider Build (xxxxx)

Additional context

OS build 26120.670 Windows App SDK 1.5.240428000 Microsoft.Windows.SDK.BuildTools 10.0.22621.756

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I get the same issue. A few of the similar issues linked above seem like they match this, but none of them have a solution.

Not working for me still by adding the following and several other variations:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   <OutputPath>bin\Release\x64\</OutputPath>
   <PublishTrimmed>true</PublishTrimmed>
   <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
 </PropertyGroup>


I have the same issue.

Windows Version: 23H2 22631.3593

Microsoft Visual Studio Community 2022 (64-bit) Version 17.10.1

If you disable Xaml generated main and replace with your own, i.e.:

public static partial class Program
{
    [LibraryImport("Microsoft.ui.xaml.dll")]
    private static partial void XamlCheckProcessRequirements();

    [STAThread]
    public static void Main(string[] args)
    {
        XamlCheckProcessRequirements();
        WinRT.ComWrappersSupport.InitializeComWrappers();

        Application.Start(_ =>
        {
            try
            {
                var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
                SynchronizationContext.SetSynchronizationContext(context);
                var app = new App();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        });
    }
}

You get the following:

The thread 108448 has exited with code 0 (0x0).
The thread 36572 has exited with code 0 (0x0).
onecore\windows\directx\database\helperlibrary\lib\directxdatabasehelper.cpp(527)\directxdatabasehelper.dll!625D1B7F: (caller: 625D6C14) ReturnHr(1) tid(20b74) 80070057 The parameter is incorrect.
onecore\windows\directx\database\helperlibrary\lib\directxdatabasehelper.cpp(527)\directxdatabasehelper.dll!625D1B7F: (caller: 625D6C14) ReturnHr(2) tid(20b74) 80070057 The parameter is incorrect.
Microsoft.ui.xaml.dll!63B57751: 80004005 - Unspecified error
Microsoft.ui.xaml.dll!63B76CC2: 80004005 - Unspecified error
Exception thrown at 0x766C98B2 (KernelBase.dll) in BlankApp.exe: WinRT originate error - 0x802B000A : 'The text associated with this error code could not be found.'.