microsoft / microsoft/WindowsAppSDK

Breakpoint experience unhelpful in WinUI Apps

Open
#5,441 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-DeveloperTools needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

When you write code that causes an exception to occur, very often the exception will be shown in App.xaml's UnhandledException handler, instead of where the exception occurred. This significantly slows down the inner developer loop, because extra time is spent trying to figure out where the exception occurred. It can also easily be (mis)interpreted as a bug with the Windows App SDK and not user code, giving a worse impression of the SDK overall.

This is part of these death-by-1000-razor cut issues that makes the developer experience really poor.

### Steps to reproduce the bug

1. Create a new WinUI project.
2. in MainWindow.xaml.cs add the following code:
```cs
public MainWindow()
{
InitializeComponent();
this.Activated += MainWindow_Activated;
}

private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
{
throw new ArgumentException(); // Imagine you do something here that occasionally causes an exception
}
```
3. Run the application and observe the exception experience:
![Image](https://github.com/user-attachments/assets/6fb73a88-8d5e-4702-89a5-40e06c565985)

### Expected behavior

This is the experience I would have preferred, which helps me faster realize the issue and allow me to move on:
![Image](https://github.com/user-attachments/assets/e979737f-bffc-40de-b505-803a9ff2e15f)
That will also give me access to the state in the thread right here and inspect what went wrong.

As a workaround this can be achieved by realizing this is an ArgumentException and turning on first-chance exceptions, but it requires being able to reproduce the issue right then and there with that first-chance break set on, but from the developer's point of view this isn't a first chance, since there is no try-catch.

Also if you repeat this example in WPF, you'll get the correct breakpoint, .

### Screenshots

_No response_

### NuGet package version

Windows App SDK 1.8 Experimental 2: 1.8.250515001-experimental2

### Packaging type

Packaged (MSIX)

### Windows version

Windows 11 version 24H2 (22621, October 2024 Update)

### IDE

Visual Studio 2022

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

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 exception in MainWindow.xaml.cs using the provided WinUI project steps, then inspect how App.xaml's UnhandledException handler affects Visual Studio break behavior. Compare the result with WPF and verify that an exception from the Activated handler breaks at its throw site with thread state available.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.