{"record":{"id":"b588cad65a022048","repo":"dotnet/maui","slug":"popasync-is-not-supported-globally-on-gtk-please","errorCode":null,"errorMessage":"PopAsync is not supported globally on GTK, please use a NavigationPage.","messagePattern":"PopAsync is not supported globally on GTK, please use a NavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/GTK/Platform.cs","lineNumber":162,"sourceCode":"\t\tprivate void HandleChildRemoved(object sender, ElementEventArgs e)\n\t\t{\n\t\t\tvar view = e.Element;\n\t\t\tDisposeModelAndChildrenRenderers(view);\n\t\t}\n\n\t\tvoid INavigation.InsertPageBefore(Page page, Page before)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"InsertPageBefore is not supported globally on GTK, please use a NavigationPage.\");\n\t\t}\n\n\t\tTask<Page> INavigation.PopAsync()\n\t\t{\n\t\t\treturn ((INavigation)this).PopAsync(true);\n\t\t}\n\n\t\tTask<Page> INavigation.PopAsync(bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"PopAsync is not supported globally on GTK, please use a NavigationPage.\");\n\t\t}\n\n\t\tTask<Page> INavigation.PopModalAsync()\n\t\t{\n\t\t\treturn ((INavigation)this).PopModalAsync(true);\n\t\t}\n\n\t\tTask<Page> INavigation.PopModalAsync(bool animated)\n\t\t{\n\t\t\tvar modal = _modals.Last();\n\t\t\t_modals.Remove(modal);\n\t\t\tmodal.DescendantRemoved -= HandleChildRemoved;\n\n\t\t\tvar modalPage = GetRenderer(modal) as Container;\n\n\t\t\tvar pageControl = PlatformRenderer.Child as IPageControl;\n\n\t\t\tDevice.BeginInvokeOnMainThread(() =>","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/GTK/Platform.cs#L144-L180","documentation":"The GTK Platform's explicit INavigation implementation does NOT support PopAsync at the global (application) navigation level — there is no global page stack to pop. PopAsync() delegates to PopAsync(true), which throws InvalidOperationException directing the developer to use a NavigationPage. (Modal pop is supported separately.)","triggerScenarios":"Calling Navigation.PopAsync() (or PopAsync(animated)) on the application-level navigation object when the root page is not a NavigationPage.","commonSituations":"Shared cross-platform code that calls Application.Current.MainPage.Navigation.PopAsync() — works on iOS/Android but not on GTK without a NavigationPage; default templates assuming global stack semantics.","solutions":["Host pages inside a NavigationPage and pop via the NavigationPage's own navigation stack (NavigationPage.PopAsync).","Use PopModalAsync for modal flows, which GTK does support globally.","Branch navigation logic per-platform or ensure a NavigationPage root on GTK."],"exampleFix":"// before — global pop (throws on GTK)\nawait Application.Current.MainPage.Navigation.PopAsync();\n// after — root is a NavigationPage\nApplication.Current.MainPage = new NavigationPage(rootPage);\nawait Application.Current.MainPage.Navigation.PopAsync();","handlingStrategy":"validation","validationCode":"static async Task SafePopAsync()\n{\n    if (Application.Current?.MainPage is NavigationPage nav)\n        await nav.Navigation.PopAsync();\n    else\n        throw new InvalidOperationException(\"PopAsync on GTK requires a NavigationPage root.\");\n}","typeGuard":"static bool CanPopGloballyOnGtk => Application.Current?.MainPage is NavigationPage nav && nav.Navigation.NavigationStack.Count > 1;","tryCatchPattern":null,"preventionTips":["Use a NavigationPage root for stack-based navigation on GTK.","Prefer PopModalAsync for modal flows (supported globally).","Guard navigation helpers with a NavigationPage-root check."],"tags":["gtk","navigation","navigationpage","not-supported","maui-compat"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}