Maui: [BUG] Popup on Android - "Could not locate MauiContext"

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Xamarin Exception Stack:
System.InvalidOperationException: Could not locate MauiContext.
  at CommunityToolkit.Maui.Views.PopupExtensions.CreatePopup(Page page, Popup popup)
  at CommunityToolkit.Maui.Views.PopupExtensions.ShowPopupAsync[ThreeButtonPopup](Page page, ThreeButtonPopup popup)
  at HemocytometerSidekick.Services.DialogManager.ShowPopupAsync(PopupViewModel popupData)
  at HemocytometerSidekick.Services.DialogManager.ShowStartResumeRequest(Action startCommand, Action resumeCommand)
  at HemocytometerSidekick.AppShell.BloodDifferential_Clicked(Object sender, EventArgs e)
  at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object )
  at Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0()
  at Java.Lang.Thread.RunnableImplementor.Run()
  at Java.Lang.IRunnableInvoker.n_Run(IntPtr , IntPtr )
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V , IntPtr , IntPtr )

Expected Behavior

Popup shouldn’t crash

Steps To Reproduce

Unsure yet

Link to public reproduction project repository

Not yet

Environment

- .NET MAUI CommunityToolkit: 3.1.0
- OS: Android 10
- .NET MAUI: 7

So far, I've seen this reported 3x in the wild but seems to be from the same device. Redmi 9A, Android 10, Spanish language

Anything else?

I’m going to fill this out more later.

Main question is what scenarios would lead to MauiContext not being found?

I saw a previous issue where the popup was being called before the app was fully loaded - a crash is fair there. But what about when it has loaded? If there are valid situations where MauiContext can’t be found while the app is running, is there a more graceful way that could be handled internally?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 36 (12 by maintainers)

Most upvoted comments

Thanks for pointing that out. Have searched with the error message before logging that as an issue and ended up here.

No, I’ve only seen it in AppCenter so far.

@BioTurboNick can you share a video reproducing the issue?

Sadly I can’t locally reproduce it yet. I’ll definitely update if I can learn more.

Off-chance idea: someone clicking and accidentally activating an edge back-swipe (so app is going to sleep before the popup can display?)

I don’t think so… Anyway would be great if you could provide a sample project… I can’t remember anything related to this. In general, we relly on MauiContext provided by Maui, so if it’s null it’s on Maui’s end… Having a repro I can debug and see if we can workaround that (: