Brainf_ckSharp
Brainf_ckSharp copied to clipboard
Double Check Microsoft.UI.Xaml Replaces Windows.UI.Xaml
When right-clicking on the Textbox, the application crashes. The following output is available in the Windows Event Viewer
Event Viewer
Faulting application name: Brainf_ckSharp.Uwp.exe, version: 1.0.0.0, time stamp: 0x5ee155af
Faulting module name: Windows.UI.Xaml.dll, version: 10.0.18362.815, time stamp: 0x9fa806f2
Exception code: 0xc000027b
Fault offset: 0x0000000000713530
Faulting process id: 0x61ec
Faulting application start time: 0x01d63f71d635f57a
Faulting application path: C:\Program Files\WindowsApps\77cee5e8-8481-4e69-92bc-31cfb2a6bc2b_1.610.1.0_x64__4tcmghg6akv1r\Brainf_ckSharp.Uwp.exe
Faulting module path: C:\Windows\System32\Windows.UI.Xaml.dll
Report Id: 22e98e81-c491-492c-9b5c-e0806edd6751
Faulting package full name: 77cee5e8-8481-4e69-92bc-31cfb2a6bc2b_1.610.1.0_x64__4tcmghg6akv1r
Faulting package-relative application ID: App
Sergio has shared a screenshot (from DevCenter?) that further implicates the issue is in Windows.UI.Xaml in the crash
I'm surprised that Windows.UI.Xaml is being used instead of Microsoft.UI.Xaml, but I'm not well versed in how the WinUI sets the types under the covers. This could well be the expected output for a crash on a WinUI ContentPresenter.
Hey Lance, just so that I understand, how did you manage to get past the initial startup crash in Release mode? I mean, if you got to repro the crash with the context menu in Release mode I take it you found a way to avoid that initial crash somehow? 🤔
I have not been able to see the initial crash, but I did fix this crash.
The controls library was not merging the resources, update Themes/Generic.xaml to:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="Brainf_ckEditBox/Brainf_ckEditBox.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Also, app.xaml in the main project should be merging the Themes dictionary:
<Application
x:Class="Brainf_ckSharp.Uwp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Dark">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
<ResourceDictionary Source="Resources/Dictionaries/Brushes.xaml"/>
<ResourceDictionary Source="Resources/Dictionaries/IconPaths.xaml"/>
<ResourceDictionary Source="Resources/Dictionaries/MDL2Icons.xaml"/>
<ResourceDictionary Source="Styles/ButtonsStyles.xaml"/>
<ResourceDictionary Source="Styles/ClassicStyles.xaml"/>
<ResourceDictionary Source="Styles/MiscStyles.xaml"/>
<ResourceDictionary Source="Styles/TextStyles.xaml"/>
<ResourceDictionary Source="Brainf_ckSharp.Uwp.Controls.Ide/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Nevermind about that last one, when I merge themes in App.xaml, it now crashes at launch
Oh, so I was merging the resource dictionaries wrong in the class library! 🤦♂️
If the startup crash you're getting is this:
Exception "The text associated with this error code could not be found. Failed to assign to property 'Windows.UI.Xaml.ResourceDictionary.Source' because the type 'Windows.Foundation.String' cannot be assigned to the type 'Windows.Foundation.Uri'. [Line: 21 Position: 37]"} System.Exception {Windows.UI.Xaml.Markup.XamlParseException}
Apparently this is fixed by leaving ms-app:///
as the URI scheme for the resources in the class library. Looks like for some reason it can't parse the URI if you don't use this format 🤔
Which is weird, because apparently the app can do that just fine instead 🤷♂️
I have two side questions:
- Why was the crash only exhibiting with .NET Native, and specifically in Release mode?
- Since I now have those WinUI
XamlControlsResources
dictionaries in both the app and the class library, should I be worried that those styles would be instantiated twice? Or would the XAML parser be able to recognize them and only create those styles once to save resources? In case that matters at all, that is, not sure how merged resources work exactly in this scenario 😅
Ah, let me try that again for the Editbox styles (thanks Resharper).
About the resources, you can't always rely on the downstream library consumer. You would think that having a style in App.xaml would make it available for everything, no matter where it comes from, but the external project is not just some XAML files that get compiled into the main project.
Rather, the library gets compiled first (only aware of Windows.UI.Xaml), while the main project is compiling for Microsoft.UI.Xaml.
I'm just making educated guesses at this point, based on the nature of the exceptions and the fact that it's .NET Native compilation stripping out the unreferenced parts.
Launch is fixed, but the context menu exception is still happening. Not sure why it stopped for a while, needing to compile with WinUI types is a red herring.
Just to double check, have you see my message in the other issue here? I mean, with "launch is fixed" you mean before or after that?
Launch has always worked for me with Release builds. Installed msix after publishing as side-loadable package)
The only reason it stopped working was because of the Uri.
Here's the packaging setting:
I see. This is weird. It makes me think there's this crash in the context menu on one end which we can investigate, and the one I'm seeing at startup which might be an SDK bug instead?
I mean, you and I are running the same exact code, and for me the app is just exploding at startup, the only difference I can see is that I'm on 19041. Which would also explain why my other app Legere is exhibiting the same exact behavior - it explodes at startup in Release as well 🤦♂️
@LanceMcCarthy By the way, we have a ton of WinUI devs in our UWP Discord server, if you wanted to join we could talk there as well! We'd be happy to have you 😊
Right now there's Steven Brix (from the WinUI team) that's asking about this issue and I'm just relaying info from here, you could talk to him directly in there if you wanted.
I'm going to take another stab at this in the morning, have to sign off. I'll have a 19041 VM spun up and will be able to hopefully be a little more helpful.
[update] just got your latest message halfway through typing, lol.
The two crashes probably do have two separate causes, but these kinds of things happen at the same time tend to make me suspect larger issue.
Sounds great, that's awesome! No worries, I'll be looking forward for an update once you have the 19041 VM setup then, that'll definitely be useful! Thanks again 😊
And yeah I definitely agree with you that all these weird issues at once are very suspicious.
I'm so tired that I completely missing ITemsPresenter and ContentPresenter, lol.
in IdeView.xaml change:
<!--IDE-->
<ide:Brainf_ckIde x:Name="CodeEditor">
<ide:Brainf_ckIde.ContextMenuSecondaryContent>
<ItemsControl
ItemsSource="{x:Bind constants:CodeSnippets.All}"
ItemTemplate="{x:Bind CodeSnippetTemplate}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ItemsPresenter">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ide:Brainf_ckIde.ContextMenuSecondaryContent>
</ide:Brainf_ckIde>
</UserControl>
To
<!--IDE-->
<ide:Brainf_ckIde x:Name="CodeEditor">
<ide:Brainf_ckIde.ContextMenuSecondaryContent>
<ItemsControl
ItemsSource="{x:Bind constants:CodeSnippets.All}"
ItemTemplate="{x:Bind CodeSnippetTemplate}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ide:Brainf_ckIde.ContextMenuSecondaryContent>
</ide:Brainf_ckIde>
</UserControl>
I feel so stupid, I mixed those two up 🤣
Thank you so much for spotting this! Commented in the other issue 👍
Closing this as I think the issue is fixed now (can right click and it works just fine). Thank you again for the help! 😄