-
Notifications
You must be signed in to change notification settings - Fork 774
Description
Describe the bug
When dynamically updating items (adding new items in the NavigationView or inside other NavigationViewItems, removing, or editing (renaming, changing properties) these items) and refreshing there is a seemingly random chance that the program will crash after collapsing the Navigation View with this error:
Exception thrown at 0x00007FFA38F366CA in Workflow.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000B7399D7240.
The debugger redirects me to App.i.g.cs (note that this file has remained unchanged). Specifically, it highlights these lines:
global::Microsoft.UI.Xaml.Application.Start((p) => {
var context = new global::Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(global::Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
global::System.Threading.SynchronizationContext.SetSynchronizationContext(context);
new App();
});Note
You might need to check "Win32 exceptions" and "Common Language Runtime Exceptions" in Visual Studio's Exception Settings to see this. Otherwise, the debugger redirects to global::System.Diagnostics.Debugger.Break(); in App.i.g.cs with no error.
Why is this important?
My specific use case:
I'm making a productivity app, where the user can create Workspaces and Folders contained within these Workspaces. The Folders can also be customized so it's easier to organize them using colors, icons, etc. The navigation between Workspaces and Folders is done through a NavigationView, since it's the most user-friendly and straightforward way to navigate between pages like this, and its built-in tree-like structure makes it easy to group pages.
Adding, removing or editing items in a NavigationView has numerous other use cases, like for file explorers, item lists, etc. I find it a core feature of an app like this, so I consider this bug to be important enough.
Steps to reproduce the bug
1.Create a NavigationView with a NavigationViewItem (example “Workspaces”) that contains subitems.
2. Dynamically add/remove subitems using code-behind (e.g., by enumerating folders in ApplicationData.Current.LocalFolder).
3. Open the app, expand/collapse the NavigationView.
4. After editing/deleting/renaming a workspace, collapse the NavigationView pane → crash.
I have made a minimal reproduction project in this repository: https://github.com/Georgios1999/NavViewCrashRepro.git
Build it in Visual Studio 2022, test it by adding, removing, recoloring, editing workspaces and folders and as you do, try to collapse the Navigation View by clicking this built-in button:

The app should eventually crash. This doesn’t always happen immediately, but after a few refresh cycles (add/remove/recolor + collapse/expand), the crash reliably occurs.
Actual behavior
App crashes with an unhandled winrt::hresult_error inside Microsoft.UI.Xaml.dll when collapsing/expanding the NavigationView. (See details and additional info for more info)
Expected behavior
The NavigationView collapses as expected.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.7.3: 1.7.250606001
Windows version
Windows Insider Build (xxxxx)
Additional context
Debug also shows
Microsoft.UI.Xaml.dll!00007FF9D855A6FF: 80004005 - Unspecified error
Exception thrown at 0x00007FFA38F366CA (KernelBase.dll) in Workflow.exe: WinRT originate error - 0x80004005 : 'Unspecified error'.
Extra info:
Windows SDK: 10.0.26100.4654
IDE: Visual Studio 2022 (latest stable)
Target framework: net8.0-windows10.0.19041.0
Note
The same exception is mentioned in #9538 but I decided to create this issue to submit more info and to document what happens in my use case. Thought that would help. If not, feel free to close this issue.