microsoft / microsoft/microsoft-ui-xaml

Poor exception handling when setting wrong connected animtation

Open
#10,605 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area-ErrorHandling bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

Describe the bug

If I call ListView.PrepareConnectedAnimation with a misspelled elementName or an incorrect item that doesn't exist in the listview, an unhelpful exception "Value does not fall in the expected range" message, but even worse the breakpoint is not hit where the exception occurred, ends up in the unhandledexception handler.

This is one of these annoying behaviors that makes working with WinUI really hard and frustrating because we don't get helpful errors and breakpoints where the errors occur.

Steps to reproduce the bug
  1. Add the following XAML to your page:
<ListView ItemClick="ListView_ItemClick" x:Name="MyListView" SelectionMode="None" IsItemClickEnabled="True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" x:Name="Title" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
  1. In code-behind add the following code:
        public MainWindow()
        {
            this.InitializeComponent();
            MyListView.ItemsSource = new string[] { "Title 1", "Title 2", "Title 3" };
        }

        private void ListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Throws because "WrongTitle" doesn't exist in xaml
            ((ListView)sender)?.PrepareConnectedAnimation("ForwardAnimation", e.ClickedItem, "WrongTitle");
            // Throws because "ABC" isn't a valid item in the list
            ((ListView)sender)?.PrepareConnectedAnimation("ForwardAnimation", "ABC", "Title");
            // Works:
            ((ListView)sender)?.PrepareConnectedAnimation("ForwardAnimation", e.ClickedItem, "Title");
        }
  1. Run the sample and observe the unhandled exception, unhelpful error message and the wrong location for the breakpoint.
Expected behavior

Error message should indicate that the "WrongTitle" object doesn't exist (first example), or that the provided item isn't a valid item in the Items collection of the listview (second example);
Furthermore Visual Studio should be breaking at this line of code, and not go to the exception handler.

Screenshots

Notice how in the exception message the actual callstack is there, but in the callstack window we're in a completely different place:
Image

NuGet package version

WinUI 3 - Windows App SDK 1.7.2: 1.7.250513003

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue through ListView.PrepareConnectedAnimation with the invalid elementName and item examples. Trace the resulting exception and call stack, then verify that invalid inputs produce specific error messages and break at the calling line instead of only reaching the unhandled-exception handler.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.