WinUI3 XAML error messages are even worse than the vague UWP ones
See original GitHub issueDescribe the bug
WinUI3 doesn’t provide design or build time indication of invalid XAML. At run-time it just gives the unhelpful “XAML parsing failed.” message.
Steps to reproduce the bug
Steps to reproduce the behavior:
- Create a new blank WinUI3 app (UWP or Desktop)
- Add this XAML to MainPage/MainWIndow
<Pivot>
<TextBlock />
</Pivot>
- Run the app
- See the crash (unhandled exception)
Expected behavior
There should be build and design time indication when the entered XAML is invalid.
The only valid children of a Pivot
control are PivotItem
s. The following is the nearest valid equivalent to the above.
<Pivot>
<PivotItem>
<TextBlock />
</PivotItem>
</Pivot>
In a UWP (WinUI2) app, with the above repro, there is a designer warning that something is wrong, but the error message is not specific about the cause. There is also no build error and attempting to run the app will lead to a runtime error.
Code | Description |
---|---|
XDG0062 | Failed to add TextBlock to ItemCollection. Element is already the child of another element. |
While this may be a technically valid explanation of what the XAML parser is doing internally to try and build an object graph from the XAML string, it is misleading and could be improved in several ways.
A better experience will include:
- The designer indicates that the specified XAML is incorrect by underlining the invalid text and having an error list entry with a meaningful description.
- Invalid XAML prevents the build from completing successfully.
- An error description that includes specific details that help address the issue. For example: “It is not possible to directly add a TextBlock to a Pivot.”
Making these changes will:
- Help developers find and fixes issues more quickly.
- Make debugging easier.
- Improve satisfaction and remove frustration with the tooling.
Screenshots
Version Info
NuGet package version: Microsoft.WinUI 3.0.0-preview4.210210.4
Windows app type:
UWP | Win32 |
---|---|
Yes | Yes |
Windows 10 version | Saw the problem? |
---|---|
Insider Build (21296.1010) | Yes |
October 2020 Update (19042) | |
May 2020 Update (19041) | |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:13
- Comments:10 (2 by maintainers)
Top GitHub Comments
I ran into #3625 myself just now and luckily found that issue via Google. Otherwise I would have had no idea what was wrong.
Debugging anything in UWP XAML was always an awful experience due to lack of information on problems compared to what you got in good old WPF XAML. Please make sure that WinUI XAML error messages are at least as detailed and specific as what you find in WPF. It’s critical if you want developers to adopt a platform.
There ought to be rule at Microsoft – punishable by being publicly mocked at weekly staff meetings – for developers who think reporting “something went wrong!” is a reasonable error message 😃.
What I find fascinating about this issue is it’s pervasive within Microsoft. It’s not just XAML parsing. It’s everywhere. I don’t know if it’s right hand not telling left hand what’s going on, or just not caring about anything that doesn’t keep someone from being able to tell their boss, “Yep, got that implemented, with error reporting!”…even though the error reporting is, in practice, useless.
It’d be fascinating to see an estimate of how many developer hours have been wasted by people using Microsoft tools on just this issue alone. I bet it’s in the millions.