microsoft / microsoft/microsoft-ui-xaml

Nested Layout causes Unspecified Error Crash

Open
#10,030 3 comments 0 reactions 0 assignees View on GitHub
area-Layouts bug
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

Running WinUI3 applications with deeply nested layout can cause a crash due to "Unspecified Error" with type Microsoft.UI.Xaml.UnhandledExceptionEventArgs.

This occurs in our application intermittently. Using more streamlined layout (for example, Panel types instead of ItemsControl types) has been found to mitigate the issue.

We are able to reproduce the issue easily with a tiny example WinUI3 application with 300 nested Grids. Although this is not a likely real-world scenario, this appears to be the same crash that occurs in our application when a reasonable amount of styled containers are nested within each other.

```
Faulting application name: winui-crash.exe, version: 1.0.0.0, time stamp: 0x66960000
Faulting module name: Microsoft.UI.Xaml.dll, version: 3.1.6.0, time stamp: 0x90636d10
Exception code: 0xc000027b
Fault offset: 0x00007e41
Faulting process id: 0x0xBA88
Faulting application start time: 0x0x1DB142DC4FE0339
Faulting application path: C:\code\@backup\winui-crash\bin\x86\Debug\net8.0-windows10.0.19041.0\win-x86\AppX\winui-crash.exe
Faulting module path: C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.6_6000.242.101.0_x86__8wekyb3d8bbwe\Microsoft.UI.Xaml.dll
Report Id: 17170d5d-452f-4306-8a7b-1975a2a849e2
Faulting package full name: 3355c9c5-d1aa-4039-8f5a-b1b535dd91e9_1.0.0.0_x86__5myfa0yag8p68
Faulting package-relative application ID: App
```

### Steps to reproduce the bug

1. Create a new WinUI3 Solution - Blank App, Packaged (WinUI 3 in Desktop)
2. Replace MainWindow.xaml and MainWindow.xaml.cs with the following code:
#### MainWindow.xaml
```

```
#### MainWindow.xaml.cs
```
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace winui_crash;
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}

private void LayoutRoot_OnLoaded(object sender, RoutedEventArgs e)
{
Grid grid = new Grid();
Grid parent = null;
LayoutRoot.Children.Add(grid);
for (int i = 0; i < 300; i++)
{
parent = grid;
grid = new Grid();
parent.Children.Add(grid);
}
}
}
```
3. Run the application.

### Expected behavior

This crash occurs well before any noticeable performance hit. When nesting a slightly smaller amount of Grids, the application launches instantly with no measurable performance problem.

Expected that no crash would occur when performance is not stressed.

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007

### Windows version

Windows 11 (22H2): Build 22621

### Additional context

Windows 11 Build 22631.
Microsoft.WindowsAppSDK 1.6.240829007

Contributor guide

Open the contributing guide

Research direction

Start with the supplied MainWindow.xaml and MainWindow.xaml.cs reproduction on Windows 11 with Windows App SDK 1.6. Reproduce the Unspecified Error using 300 nested Grid instances, then compare behavior as the nesting depth and container types change. Done means the nested-layout scenario no longer crashes under the reported conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.