Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App.UnhandledException on XamarinFormsNav.PopAsync(true) #18467

Closed
sjorsmiltenburg opened this issue Nov 1, 2023 · 6 comments
Closed

App.UnhandledException on XamarinFormsNav.PopAsync(true) #18467

sjorsmiltenburg opened this issue Nov 1, 2023 · 6 comments
Labels
area-navigation NavigationPage platform/windows 🪟 s/needs-repro Attach a solution or code which reproduces the issue s/no-recent-activity Issue has had no recent activity s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@sjorsmiltenburg
Copy link

sjorsmiltenburg commented Nov 1, 2023

Description

I have a semi-reproducable blocking bug in my main app where, when I navigate back on certain views and I get a

UnhandledException with Microsoft.UI.Xaml.Controls.Frame.NavigationFailed was unhandled.
Inner Exception Message = "Catastrophic failure (0x8000FFFF (E_UNEXPECTED))"

caught in the App.UnhandledExceptionEventHandler
However afterwards it also hits my catch block where I see the exception as a

"Error HRESULT E_FAIL has been returned from a call to a COM component" when calling XamarinFormsNav.PopAsync(true);

with the call stack mentioned below

If I swallow this exception there is still a view on the navstack, but visually I end up in an empty looking view (blank page with no controls)

Steps to Reproduce

I'm unable to pinpoint what exactly is causing this.

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

no

Relevant log output

at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.Controls.IContentPresenterMethods.set_Content(IObjectReference _obj, Object value)
   at Microsoft.UI.Xaml.Controls.ContentPresenter.set_Content(Object value)
   at Microsoft.Maui.Platform.StackNavigationManager.OnNavigated(Object sender, NavigationEventArgs e)
   at WinRT._EventSource_global__Microsoft_UI_Xaml_Navigation_NavigatedEventHandler.EventState.<GetEventInvoke>b__1_0(Object sender, NavigationEventArgs e)
   at ABI.Microsoft.UI.Xaml.Navigation.NavigatedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.Controls.IFrameMethods.GoBack(IObjectReference _obj, NavigationTransitionInfo transitionInfoOverride)
   at Microsoft.UI.Xaml.Controls.Frame.GoBack(NavigationTransitionInfo transitionInfoOverride)
   at Microsoft.Maui.Platform.StackNavigationManager.NavigateTo(NavigationRequest args)
   at Microsoft.Maui.Handlers.NavigationViewHandler.RequestNavigation(INavigationViewHandler arg1, IStackNavigation arg2, Object arg3)
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
   at Microsoft.Maui.Controls.NavigationPage.Microsoft.Maui.IStackNavigation.RequestNavigation(NavigationRequest eventArgs)
   at Microsoft.Maui.Controls.NavigationPage.<SendHandlerUpdateAsync>d__100.MoveNext()
   at Microsoft.Maui.Controls.NavigationPage.MauiNavigationImpl.<OnPopAsync>d__7.MoveNext()
   at BB.Maui.Services.NavService.<<GoBack>b__12_0>d.MoveNext() in C:\_Sources\BookaBooka\BB.Maui\Services\NavService.cs:line 79
@sjorsmiltenburg sjorsmiltenburg added the t/bug Something isn't working label Nov 1, 2023
@samfoucart
Copy link

samfoucart commented Nov 15, 2023

I am encountering a similar issue when I use Application.Current.MainPage.ShowPopup(myView()) from the Community Toolkit. If I swallow the Catastrophic Failure exception, on Windows I get a blank page that looks like this. And if I do myView.Close() this page doesn't go away, and it can't be navigated away from.
image

It always happens on a specific view in my application, but I cannot figure out what is unique about this view for me to make a minimum reproducible sample. When I try to isolate it, the bug stops happening. But when I put the view back into the application, it happens 100% of the time.

My issue does seem to be a little unrelated, but there might be some similarities

System.Runtime.InteropServices.COMException
HResult=0x8000FFFF
Message=Catastrophic failure

Source=WinRT.Runtime
StackTrace:
at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.Controls.Primitives.IPopupMethods.set_IsOpen(IObjectReference _obj, Boolean value)
at Microsoft.UI.Xaml.Controls.Primitives.Popup.set_IsOpen(Boolean value)
at CommunityToolkit.Maui.Core.Handlers.PopupHandler.MapOnOpened(PopupHandler handler, IPopup view, Object result)
at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
at CommunityToolkit.Maui.Views.PopupExtensions.PlatformShowPopup(Popup popup, IMauiContext mauiContext)
at CommunityToolkit.Maui.Views.PopupExtensions.CreateAndShowPopup[TPopup](Page page, TPopup popup)
at CommunityToolkit.Maui.Views.PopupExtensions.<>c__DisplayClass0_0`1.g__handler|0(Object sender, EventArgs args)
at Microsoft.Maui.Controls.VisualElement.OnLoadedCore()
at Microsoft.Maui.Controls.VisualElement.HandlePlatformUnloadedLoaded()
at Microsoft.Maui.Controls.VisualElement.add_Loaded(EventHandler value)
at CommunityToolkit.Maui.Views.PopupExtensions.ShowPopup[TPopup](Page page, TPopup popup)
at Odyssey.Services.UserDialogService.<>c__DisplayClass8_0.b__0() in \Services\UserDialogService.cs:line 116

This exception was originally thrown at this call stack:
[External Code]
Services.UserDialogService.OpenLoadingPopup.AnonymousMethod__0() in UserDialogService.cs

@bengiles
Copy link

bengiles commented Feb 8, 2024

same

ExceptionHelpers.g__Throw|39_0 (Int32 hr)

System.Runtime.InteropServices.COMException

WinRT
ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0 (Int32 hr)
ABI.Microsoft.UI.Xaml.Controls
IContentPresenterMethods.set_Content (IObjectReference _obj, Object value)
Microsoft.Maui.Platform
StackNavigationManager.OnNavigated (Object sender, NavigationEventArgs e)
ABI.Microsoft.UI.Xaml.Navigation
NavigatedEventHandler.Do_Abi_Invoke (IntPtr thisPtr, IntPtr sender, IntPtr e)
WinRT
ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0 (Int32 hr)
ABI.Microsoft.UI.Xaml.Controls
IFrameMethods.GoBack (IObjectReference _obj, NavigationTransitionInfo transitionInfoOverride)
Microsoft.Maui
CommandMapper.InvokeCore (String key, IElementHandler viewHandler, IElement virtualView, Object args)
Microsoft.Maui.Handlers
ElementHandler.Invoke (String command, Object args)
Microsoft.Maui.Controls
ShellSection.OnPopAsync (Boolean animated)
Microsoft.Maui.Controls
ShellSection.PrepareCurrentStackForBeingReplaced (ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable`1 animate, List`1 globalRoutes, Boolean isRelativePopping)
Microsoft.Maui.Controls
ShellSection.GoToAsync (ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable`1 animate, Boolean isRelativePopping)
Microsoft.Maui.Controls
ShellNavigationManager.GoToAsync (ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest)
Microsoft.Maui.Controls.ShellSection
NavigationImpl.OnPopAsync (Boolean animated)
ReportWriter.MultiPlatform.App.Services.MauiNavigationService.<>c
<<PopAsync>b__9_0>d.MoveNext ()
AsyncAwaitBestPractices
SafeFireAndForgetExtensions.HandleSafeFireAndForget[TException] (Task task, Boolean continueOnCapturedContext, Action`1 onException)
System.Threading.Tasks.Task
<>c.<ThrowAsync>b__128_0 (Object state)
Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext
<>c__DisplayClass2_0.<Post>b__0 ()
WinRT
ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0 (Int32 hr)
ABI.Windows.ApplicationModel.Core
IUnhandledErrorMethods.Propagate (IObjectReference _obj)
Windows.ApplicationModel.Core
UnhandledError.Propagate ()
Microsoft.AppCenter.Utils
ApplicationLifecycleHelperWinUI.<ctor>b__0_3 (Object sender, UnhandledErrorDetectedEventArgs eventArgs)

@samfoucart
Copy link

@bengiles I figured out a solution to my problem btw. I forgot to ever update my comment.

My issue specifically happens when you get to a page by calling Navigation.PushModalAsync. Our application was using the dependency FreshMvvm.Maui. We migrated this app from Xamarin, and it was using that dependency to handle navigation, but this should be reproducible without that dependency. As long as you're on a page inheriting from NavigationPage, and push a modal, if you then call Application.Current.MainPage.ShowPopup(...), you will get this exception. This exception happens because the Application.Current.MainPage is not the actual page you're on if you're in a Modal.

To solve this, we did

_loadingPopup = new LoadingPopup(message ?? " ");
if (Application.Current != null)
{
    if (Application.Current.MainPage != null)
    {
        Page mainPage = Application.Current.MainPage;
        if (mainPage.Navigation.ModalStack.Count == 0)
        {
            mainPage.ShowPopup(_loadingPopup);
        }
        else
        {
            IReadOnlyList<Page> stack = mainPage.Navigation.ModalStack;
            stack[stack.Count - 1].ShowPopup(_loadingPopup);
        }
    }
}

My issue was specific to the Popups from the Maui community toolkit, but I'm guessing that doing most actions to Application.Current.MainPage while you're in a modal will cause this exception.

@samfoucart
Copy link

I haven't looked through the Maui Community Toolkit's issues to see if this is reported, or known. If there isn't one, then I can create an issue with some reproducible steps related to the ShowPopup function.

@kevinxufei kevinxufei added the s/triaged Issue has been reviewed label May 27, 2024
@jsuarezruiz jsuarezruiz added the s/needs-repro Attach a solution or code which reproduces the issue label Jun 6, 2024
Copy link
Contributor

Hi @sjorsmiltenburg. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Jun 11, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-navigation NavigationPage platform/windows 🪟 s/needs-repro Attach a solution or code which reproduces the issue s/no-recent-activity Issue has had no recent activity s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants