{"record":{"id":"6b74534e798c8831","repo":"dotnet/maui","slug":"insertpagebefore-is-not-supported-globally-on-gtk","errorCode":null,"errorMessage":"InsertPageBefore is not supported globally on GTK, please use a NavigationPage.","messagePattern":"InsertPageBefore 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":152,"sourceCode":"\t\t\tif (viewRenderer == null)\n\t\t\t{\n\t\t\t\tviewRenderer = CreateRenderer(mainPage);\n\t\t\t\tSetRenderer(mainPage, viewRenderer);\n\n\t\t\t\tPlatformRenderer.Add(viewRenderer.Container);\n\t\t\t\tPlatformRenderer.ShowAll();\n\t\t\t}\n\t\t}\n\n\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)","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/GTK/Platform.cs#L134-L170","documentation":"The GTK Platform's explicit INavigation implementation deliberately does NOT support InsertPageBefore at the global (application) navigation level. Calling it throws InvalidOperationException directing the developer to use a NavigationPage instead, because GTK global navigation has no page-stack to insert into.","triggerScenarios":"Invoking INavigation.InsertPageBefore on the application-level navigation (obtained without a NavigationPage), i.e. trying to manipulate the global page stack on GTK.","commonSituations":"Code written for a platform that supports global InsertPageBefore (e.g. the default Xamarin.Forms navigation) being run on GTK without a NavigationPage root; shared navigation helpers that assume global stack operations.","solutions":["Wrap the page hierarchy in a NavigationPage and call InsertPageBefore on the NavigationPage's navigation (NavigationPage.Navigation.InsertPageBefore).","Restructure so all stack-manipulating navigation goes through a NavigationPage on GTK.","Guard platform-specific navigation calls behind a runtime/platform check."],"exampleFix":"// before — global insert (throws on GTK)\nApplication.Current.MainPage.Navigation.InsertPageBefore(newPage, currentPage);\n// after — use a NavigationPage\nvar nav = new NavigationPage(rootPage);\nApplication.Current.MainPage = nav;\nnav.Navigation.InsertPageBefore(newPage, currentPage);","handlingStrategy":"validation","validationCode":"static void SafeInsertBefore(Page page, Page before)\n{\n    var nav = Application.Current?.MainPage as NavigationPage\n        ?? throw new InvalidOperationException(\"Use a NavigationPage root to insert pages on GTK.\");\n    nav.Navigation.InsertPageBefore(page, before);\n}","typeGuard":"static bool HasNavigationPageRoot => Application.Current?.MainPage is NavigationPage;","tryCatchPattern":null,"preventionTips":["Root the GTK app in a NavigationPage to enable stack operations.","Branch navigation code per platform or guard on NavigationPage root.","Avoid calling global INavigation stack ops on GTK."],"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"}