Microsoft-ui-xaml: XAML Parsing Exception Messages are not Useful

Created on 19 Aug 2020  ·  3Comments  ·  Source: microsoft/microsoft-ui-xaml

I was asked to open an issue by @stevenbrix when I mentioned this over on the August 19th community call announcement. Note that in my case, I was creating WinUI Desktop applications.

I find the XAML Parsing exception messages to be near useless when trying to correct parsing mistakes. I have an extensive background in WPF application development so its not as if I am new to using XAML.

While trying to port a small subset of XAML libraries over to WinUI, not a single exception message has been useful in helping me resolve my problems. Although I have not been logging a tally of those, the following example is typical of what I have encountered.

Example of Error Messages for a simple XAML Error

Take for example the mistake that I made when defining a XAML StaticResource for the type "Double". I thought that I could add a using for System and then define the resource with sys:Double. As you can see from the exception message below, it would be extremely difficult to know what type of XAML parsing error had occurred. It doesn't even point to the assembly that actually caused the error let alone have a warm hint of what the problem was. When issues like this occur, I have to start backing out each and every block of XAML until the code runs without exception. Since it takes much longer to launch a packaged application, its a very tedious, time consuming and error prone process.

Writing raw XAML is error prone, but when porting hundreds of XAML files from WPF, errors are unavoidable. My mistake was using sys:Double instead of x:Double.

xmlns:sys="using:System"
...
<sys:Double x:Key="DoubleKey">.5</sys:Double>
Microsoft.UI.Xaml.dll!7A6F17CF: (caller: 7A471CB9) Exception(1) tid(85cc) 80004005 Unspecified error
Exception thrown at 0x76119862 in Oceanside.VirtualKeyboard.Sample.App.exe: Microsoft C++ exception: wil::ResultException at memory location 0x00D79C40.
Exception thrown at 0x76119862 in Oceanside.VirtualKeyboard.Sample.App.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Microsoft.UI.Xaml.dll!7A6F2F43: (caller: 7A4CE21A) ReturnHr(1) tid(85cc) 80004005 Unspecified error
    Msg:[Microsoft.UI.Xaml.dll!7A6F17CF: (caller: 7A471CB9) Exception(1) tid(85cc) 80004005 Unspecified error
] 
Exception thrown: 'Microsoft.UI.Xaml.Markup.XamlParseException' in winrt.runtime.dll
WinRT information: Could not create a new view because the main window has not yet been created
An exception of type 'Microsoft.UI.Xaml.Markup.XamlParseException' occurred in winrt.runtime.dll but was not handled in user code
WinRT information: Could not create a new view because the main window has not yet been created
XAML parsing failed.
team-Markup winui3preview

Most helpful comment

Agreed, this has been discussed a few places before as well. I haven't been able to locate the issues to link to though.

All 3 comments

Agreed, this has been discussed a few places before as well. I haven't been able to locate the issues to link to though.

Thanks for the follow up @jtbrower and @robloo, sorry for the slow response. This should be improved in 16.8 and 16.9 Preview 1, where the Microsoft.UI.Xaml.Markup.XamlParseException should be enabled by default.

@robloo thanks for linking those other issues. I know the experience still isn't great, so I'm not going to close this issue out, as we can keep it open to track this.

Was this page helpful?
0 / 5 - 0 ratings