question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WinUI3 XAML error messages are even worse than the vague UWP ones

See original GitHub issue

Describe 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:

  1. Create a new blank WinUI3 app (UWP or Desktop)
  2. Add this XAML to MainPage/MainWIndow
     <Pivot>
        <TextBlock />
    </Pivot>
  1. Run the app
  2. 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 PivotItems. 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

image

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:open
  • Created 3 years ago
  • Reactions:13
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
billhenncommented, Feb 23, 2021

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.

3reactions
markolbertcommented, Apr 11, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XAML Errors and Warnings - Visual Studio (Windows)
When authoring XAML, Visual Studio analyzes the code as you type. A squiggle appears on a line of code when an error is...
Read more >
[Visual Studio 2019 version 16.10][UWP][Xamarin] Runtime ...
The .NET native app fails at launch with an 0xc000027b error code. This is a stowed exception, which means that there's a stored...
Read more >
What's supported when migrating from UWP to WinUI 3
Today in version 1.3 of the Windows App SDK, launch speeds, RAM usage, and installation size of WinUI 3 apps are larger/slower than...
Read more >
Is WinUI really production ready? : r/dotnet
Good question, even though some things are missing from UWP XAML, it offers performance improvements over WPF XAML, which is a great selling ......
Read more >
c# - I am getting 'A project cannot have more than one ...
The error is caused by that you have multiple Application XAML item. To fix this issue you can search the project with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found