microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
WinRT originate error - 0x80004005 : 'Unspecified error'.
Describe the bug
Using WinUI-3 and the NavigationView, I'm getting a bizzare error deep in the WinUI core.
Exception thrown at 0x00007FFDEFC6474C (KernelBase.dll) in ThetaRex.OpenBook.Desktop.exe: WinRT originate error - 0x80004005 : 'Unspecified error'.
Here's the code where it happens, but this doesn't tell the whole story:
/// <inheritdoc/>
public async Task NavigateToAsync(Type type, object key = null)
{
// Navigate away from the current page (if it exists).
if (this.NavigationStack.Count > 0)
{
INavigable navigableFrom = this.NavigationStack[this.NavigationStack.Count - 1];
await navigableFrom.NavigateFromAsync(navigableFrom.Key);
}
// Navigate to the new page.
var page = this.viewMap[type]();
this.NavigationView.Content = page;
var navigableTo = page.DataContext as INavigable;
if (navigableTo != null)
{
page.DataContext = navigableTo;
this.NavigationStack.Add(navigableTo); <--------- Crash happens here.
await navigableTo.NavigateToAsync(key);
}
}
The 'NavigationStack' is just a simple list of view models:
/// <inheritdoc/>
public ObservableCollection<INavigable> NavigationStack { get; } = new ObservableCollection<INavigable>();
And, this is where it gets strange, this collection of view models is bound to the 'BreadcrumbBar' control:
<Style x:Key="BreadcrumbBarStyle"
TargetType="BreadcrumbBar">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Button BorderThickness="0"
Command="{Binding GoTo}"
Content="{Binding Name}"
FontSize="26"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
If I remove the bindings from the breadcrumb bar, we don't crash (not really an option).
Steps to reproduce the bug
Sorry, but I can't even reproduce this bug.
If I take the same code and compile it on a Windows 2019 DataServer, then it works. If I spin up a virtual machine with Windows 11, it works. The Release build works, the Debug build fails.
I suspected some corruption on my laptop, so I wiped it clean. Installed a fresh copy of Windows 11, fresh copy of Visual Studio, and it crashed in the same place in Debug. Ran without trouble in Release.
Expected behavior
I expect the NavigationView to navigate to the given target and I expect the Breadcrumb control to reflect that position in the navigation hierarchy.
Screenshots
NuGet package version
No response
Windows app type
- [ ] UWP
- [X] Win32
Device form factor
Desktop
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response