I am having an issue with a MAUI app where very rarely, I get an unhandled NavigationFailed exception. I have one main view, which navigates to a secondary page with the following:
await Shell.Current.GoToAsync($"{nameof(AddCollectionPage)}", true, new Dictionary<string, object>
{
{"Contracts", queryStringBuilder.ToString() }
});
then there is a button within that second page which returns backwards, using the following:
await Shell.Current.GoToAsync("../");
Now this works fine, and probably 999 out of 1000 times there are no issues... But rarely, the app crashes. Whilst debugging, I it breaks at the UnhandledException point within App.g.i.cs at this code:
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
The exception isn't all that useful.
The call stack consists of just 4 entries - 2 of which are external code, 1 is the location I posted within App.g.i.cs and the other is the line where it calls the shell navigation.
This was hit just now, at the point in the code where I called Navigation to go to "../" from the secondary page back to the main one. Its a really rare occurrence, but frequent enough to be pretty annoying.
When I wrap the line calling GoToAsync which causes the crash in a try catch and log the exception it catches, I get the following info (error and stack trace). The bottom line of which references the part of my code calling GoToAsync, with everything else being MAUI framework stuff.
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.Controls.IFrameMethods.GoBack(IObjectReference _obj, NavigationTransitionInfo transitionInfoOverride)
at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
at Microsoft.Maui.Controls.ShellSection.OnPopAsync(Boolean animated)
at Microsoft.Maui.Controls.ShellSection.PrepareCurrentStackForBeingReplaced(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable`1 animate, List`1 globalRoutes, Boolean isRelativePopping)
at Microsoft.Maui.Controls.ShellSection.GoToAsync(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable`1 animate, Boolean isRelativePopping)
at Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest)
at BlurFarm.ViewModels.AddCollectionPageViewModel.SelectCollection(Collection collection)