microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.28k stars 675 forks source link

Crash in FrameworkApplication::StartDesktop() when packaged #5746

Open mqudsi opened 3 years ago

mqudsi commented 3 years ago

Describe the bug

My WinUI3 project built against Project Reunion 0.8.2 is crashing on startup when deployed via the MS Store or via a published side loading .msixbundle file. It runs fine if deployed exploded via Visual Studio directly from the Debug/Release folder.

The error message from the minidump:

Unhandled exception at 0x00007FF9A4E4BD3E (KERNELBASE.dll) in Foo.exe.604.dmp: 0xC000027B: An application-internal exception has occurred (parameters: 0x000001656E5DB4C0, 0x0000000000000003).

The stack trace is not very helpful:

    KERNELBASE.dll!RaiseFailFastException()    Unknown
    combase.dll!RoFailFastWithErrorContextInternal2(HRESULT hrError, unsigned long cStowedExceptions, _STOWED_EXCEPTION_INFORMATION_V2 * * aStowedExceptionPointers) Line 1455  C++
    Microsoft.UI.Xaml.dll!DirectUI::FrameworkApplication::StartDesktop()    Unknown
    Microsoft.UI.Xaml.dll!DirectUI::FrameworkApplicationFactory::Start()    Unknown
    [Managed to Native Transition]  
    Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStatics.Microsoft.UI.Xaml.IApplicationStatics.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Unknown
    Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback)   Unknown
>   PrayerGuardian.dll!PrayerGuardian.Program.Main() Line 41    C#
    System.Private.CoreLib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Line 48  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 186  C#
    System.Private.CoreLib.dll!System.Threading.ThreadHelper.ThreadStart() Line 98  C#
    [Native to Managed Transition]  
    kernel32.dll!BaseThreadInitThunk() Unknown
    ntdll.dll!RtlUserThreadStart() Unknown

and an alternate stack trace from WinDbg:

00000208`bfbf3760 00007ff9`a681d1e1 combase!RoOriginateError+0x51
00000208`bfbf3768 00007ff9`5c4bbf9e Microsoft_UI_Xaml!DirectUI::FrameworkApplication::InvokeOnLaunchActivated+0x16edd2
00000208`bfbf3770 00007ff9`5c31a190 Microsoft_UI_Xaml!DirectUI::FrameworkApplication::StartOnCurrentThreadImpl+0x124
00000208`bfbf3778 00007ff9`5c319cd6 Microsoft_UI_Xaml!DirectUI::FrameworkApplicationGenerated::StartOnCurrentThread+0x26
00000208`bfbf3780 00007ff9`5c24db63 Microsoft_UI_Xaml!DirectUI::WindowsXamlManager::XamlCore::Initialize+0xef
00000208`bfbf3788 00007ff9`5c24e7c8 Microsoft_UI_Xaml!DirectUI::WindowsXamlManager::Initialize+0xa8
00000208`bfbf3790 00007ff9`5c1fdb13 Microsoft_UI_Xaml!ctl::ComObjectBase::CreateInstanceBase+0x13
00000208`bfbf3798 00007ff9`5c3b961d Microsoft_UI_Xaml!ctl::make<DirectUI::WindowsXamlManager>+0x4d
00000208`bfbf37a0 00007ff9`5c3b9569 Microsoft_UI_Xaml!DirectUI::WindowsXamlManagerFactory::InitializeForCurrentThreadImpl+0x21
00000208`bfbf37a8 00007ff9`5c3b9527 Microsoft_UI_Xaml!DirectUI::WindowsXamlManagerFactory::InitializeForCurrentThread+0x27
00000208`bfbf37b0 00007ff9`5c319f2d Microsoft_UI_Xaml!DirectUI::FrameworkApplication::StartDesktop+0x169
00000208`bfbf37b8 00007ff9`5c319d63 Microsoft_UI_Xaml!DirectUI::FrameworkApplicationFactory::Start+0x63

with the following details:

CONTEXT:  (.ecxr)
rax=0000005323dfebb0 rbx=0000005323dff1c0 rcx=0000005323dfebb0
rdx=0000000000000000 rsi=00000208bfbc5de0 rdi=0000005323dfebb0
rip=00007ff9a4e4bd3e rsp=0000005323dfead0 rbp=0000000000000000
 r8=0000000000000000  r9=0000000000000000 r10=00000208bfbd9970
r11=0000005323dff1c0 r12=0000000000000001 r13=0000000000000000
r14=0000000000000001 r15=0000000000000002
iopl=0         nv up ei pl nz na po nc
cs=0033  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000204
KERNELBASE!RaiseFailFastException+0x16e:
00007ff9`a4e4bd3e 0f1f440000      nop     dword ptr [rax+rax]
Resetting default scope

FAULTING_IP: 
KERNELBASE!RaiseFailFastException+16e
00007ff9`a4e4bd3e 0f1f440000      nop     dword ptr [rax+rax]

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ff9a4e4bd3e (KERNELBASE!RaiseFailFastException+0x000000000000016e)
   ExceptionCode: c000027b
  ExceptionFlags: 00000001
NumberParameters: 2
   Parameter[0]: 00000208bfbc5de0
   Parameter[1]: 0000000000000003

DEFAULT_BUCKET_ID:  STOWED_EXCEPTION

PROCESS_NAME:  PrayerGuardian.exe

BUGCHECK_STR:  STOWED_EXCEPTION

ERROR_CODE: (NTSTATUS) 0xc000027b - An application-internal exception has occurred.

EXCEPTION_CODE: (HRESULT) 0x802b000a (2150301706) - <Unable to get error code text>

EXCEPTION_CODE_STR:  802b000a

EXCEPTION_PARAMETER1:  00000208bfbc5de0

EXCEPTION_PARAMETER2:  0000000000000003

Steps to reproduce the bug

Unknown

Version Info

NuGet package version:

WinUI 3 - Project Reunion 0.8: [0.8.2]

Windows app type: UWP Win32
No Yes
Windows version Saw the problem?
Insider Build (xxxxx)
May 2021 Update (19043)
October 2020 Update (19042) Yes
May 2020 Update (19041)
November 2019 Update (18363) Yes
May 2019 Update (18362) Yes
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

A XamlParseException is thrown at startup when the package is deployed via an msixbundle rather than run from the exploded bin folder.

Microsoft.UI.Xaml.Markup.XamlParseException: XAML parsing failed.
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
mqudsi commented 3 years ago

The downstream cause is a XamlParseException in MainWindow's InitialComponent() with the following stack trace:

Microsoft.UI.Xaml.Markup.XamlParseException: XAML parsing failed.
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr) in WinRT.Runtime.dll:token 0x60003cd+0x1c
   at ABI.Microsoft.UI.Xaml.IApplicationStatics.global::Microsoft.UI.Xaml.IApplicationStatics.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation) in Microsoft.WinUI.dll:token 0x600159a+0x47
   at Microsoft.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation) in Microsoft.WinUI.dll:token 0x600ae88+0x0
   at PrayerGuardian.MainWindow.InitializeComponent() in PrayerGuardian.dll:token 0x60000af+0x1b
   at PrayerGuardian.MainWindow..ctor() in PrayerGuardian.dll:token 0x60000ab+0x10

The internal message is

Cannot locate resource from 'ms-appx:///MainWindow.xaml'.

This happens even with a new blank desktop window template (BlankWindow1) used instead of my existing MainWindow : Window instance (which only contains a single <Frame /> element, anyway).

No Window methods are overridden, there's no Activated handler (and even if there were, it wouldn't have been installed yet at this point). The MainWindow instance is initialized in override OnLaunched in App.xaml.cs:

        protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
        {
            MainWindow = new MainWindow();
            MainWindow.Activate();
        }

but since it is terminating in the new MainWindow() call, MainWindow.Activate() is not even being reached.

The App.xaml contents are similarly non-descript:

<Application
    x:Class="PrayerGuardian.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:PrayerGuardian">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                <!--  Other merged dictionaries here  -->
            </ResourceDictionary.MergedDictionaries>
            <!--  Other app resources here  -->
        </ResourceDictionary>
    </Application.Resources>
</Application>

Again, this only happens on any other machine besides mine - locally, it runs flawlessly. The application is always packaged and deployed via the MSIX side load installer. The application was created under 18363 with Visual Studio 2019 16.11.0 Preview 3.0.


These are the stowed exceptions:

Stowed Exception Array @ 0x000001d2f8863300

Stowed Exception #1 @ 0x000001d2f8882d00
    0x802B000A (FACILITY_XAML - XAML): Unknown Error

    Stack    : 0x1d2f8881018
        7fff623ac024 Microsoft_UI_Xaml!DirectUI::FrameworkApplicationGenerated::OnLaunchedProtected+0x16ed20
        7fff6223d2b3 Microsoft_UI_Xaml!DirectUI::FrameworkApplication::InvokeOnLaunchActivated+0xe7
        7fff6220a190 Microsoft_UI_Xaml!DirectUI::FrameworkApplication::StartOnCurrentThreadImpl+0x124
        7fff62209cd6 Microsoft_UI_Xaml!DirectUI::FrameworkApplicationGenerated::StartOnCurrentThread+0x26
        7fff6213db63 Microsoft_UI_Xaml!DirectUI::WindowsXamlManager::XamlCore::Initialize+0xef
        7fff6213e7c8 Microsoft_UI_Xaml!DirectUI::WindowsXamlManager::Initialize+0xa8
        7fff620edb13 Microsoft_UI_Xaml!ctl::ComObjectBase::CreateInstanceBase+0x13
        7fff622a961d Microsoft_UI_Xaml!ctl::make<DirectUI::WindowsXamlManager>+0x4d
        7fff622a9569 Microsoft_UI_Xaml!DirectUI::WindowsXamlManagerFactory::InitializeForCurrentThreadImpl+0x21
        7fff622a9527 Microsoft_UI_Xaml!DirectUI::WindowsXamlManagerFactory::InitializeForCurrentThread+0x27
        7fff62209f2d Microsoft_UI_Xaml!DirectUI::FrameworkApplication::StartDesktop+0x169
        7fff62209d63 Microsoft_UI_Xaml!DirectUI::FrameworkApplicationFactory::Start+0x63
        7fff04f346dd

Stowed Exception #2 @ 0x000001d2f88786a0
    0x80004005 (FACILITY_NULL - Default): E_FAIL - Unspecified failure

    Stack    : 0x1d2f88769b8
        7fff62384215 Microsoft_UI_Xaml!CCoreServices::LoadXamlResource+0x1a2555
        7fff621cf657 Microsoft_UI_Xaml!CApplication::LoadComponent+0x16b
        7fff621bf030 Microsoft_UI_Xaml!Application_LoadComponent+0xa4
        7fff621bed62 Microsoft_UI_Xaml!DirectUI::FrameworkApplication::LoadComponent+0xde
        7fff621bec55 Microsoft_UI_Xaml!DirectUI::FrameworkApplicationFactory::LoadComponentWithResourceLocationImpl+0x7d
        7fff621bebaa Microsoft_UI_Xaml!DirectUI::FrameworkApplicationFactory::LoadComponentWithResourceLocation+0x4a
        7fff051481fa

(Sidenote, instructions on accessing stowed exceptions could use some work. !pde.dse requires a memory address, but it's not the address of the thrown c000027b exception. I ended up using !dpx -dse to get the stowed exceptions and their addresses, then inspecting those addresses with !pde.dse <addr>)

mqudsi commented 3 years ago

There seems to be something wrong with how the XAML resources are being packaged - the crash is not machine-dependent at all, but rather dependent on the method of deployment. When the Package project is deployed via Visual Studio and the resulting app is installed out of the bin/[Debug|Release] folder, everything works fine. When the package is published as a .msixbundle and that MSIX is installed/deployed, the application crashes at startup when it fails to load resources from ms-appx:///MainWindow.xaml.

I've updated the initial post accordingly.

mqudsi commented 3 years ago

resources.pri does not include any of the compiled xaml .xbf resources for apps suffering from this.

The problem is that Prep_ComputeProcessXamlFiles does not run because '@(ApplicationDefinition)'!='' or '@(Page)'!='' does not evaluate to true (App.xaml correctly has its compile property set to "Application Definition" and MainWindow.xaml has its compile property set to "Page" - don't go chasing after them, red herring, wrong tree, yada yada.)

This occurs if ProjectReunion.WinUi is installed as a transitive dependency - it must (also) be directly referenced in the project.

The tooling surrounding WinUI is extremely fragile, emits terribly opaque errors, and is not well documented. Hopefully this helps someone.

asklar commented 3 years ago

@drustheaxe FYI

DrusTheAxe commented 3 years ago

This occurs if ProjectReunion.WinUi is installed as a transitive dependency

This sounds like the Universal Windows / ...Transitive... issue that plagued MrtCoreManagedTest last week.

@Scottj1s any thoughts? You're more the VS-project-Jedi-master than I ;-)

mqudsi commented 3 years ago

@DrusTheAxe I think when I was browsing some of the older WindowsAppSDK issues a couple of weeks ago IIRC you were bringing up tooling concerns regarding shipping WinUI and WindowsAppSDK only via NuGet to start. Presumably this is something else you can add to the list of concerns if you ever wanted to ship them as vcpkg dependencies, since the nuget package is doing more than just pulling in some libraries here.

StephenLPeters commented 3 years ago

@llongley @DrusTheAxe's decriptions sounds similar to the issue we had with Winui2 being included transitively. Ring any bells?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

mattico commented 1 year ago

Bump.

benaclejames commented 1 year ago

Bump here too Seems to have only started happening recently