{"record":{"id":"0b5e6660b25623c6","repo":"dotnet/maui","slug":"insertpagebefore-is-not-supported-globally-on-ios","errorCode":null,"errorMessage":"InsertPageBefore is not supported globally on iOS, please use a NavigationPage.","messagePattern":"InsertPageBefore is not supported globally on iOS, please use a NavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/iOS/Platform.cs","lineNumber":90,"sourceCode":"\n\t\tprotected virtual void Dispose(bool disposing)\n\t\t{\n\t\t\tif (_disposed)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t_disposed = true;\n\n\t\t\tif (disposing)\n\t\t\t{\n\t\t\t\t_renderer.Dispose();\n\t\t\t}\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 iOS, please use a NavigationPage.\");\n\t\t}\n\n\t\tIReadOnlyList<Page> INavigation.ModalStack\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif (_disposed)\n\t\t\t\t\treturn new List<Page>();\n\n\t\t\t\treturn _modals;\n\t\t\t}\n\t\t}\n\n\t\tIReadOnlyList<Page> INavigation.NavigationStack\n\t\t{\n\t\t\tget { return new List<Page>(); }\n\t\t}\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Platform.cs#L72-L108","documentation":"Platform.cs (the global Platform, not NavigationPage) explicitly throws InvalidOperationException for INavigation.InsertPageBefore because global navigation is not supported on iOS — navigation stack management requires a NavigationPage. The global INavigation is a limited shim that only supports modal push/pop.","triggerScenarios":"Calling Navigation.InsertPageBefore on the Application.MainPage.Navigation when MainPage is not a NavigationPage; reaching the Platform-level INavigation via the global accessor.","commonSituations":"Code that assumes MainPage.Navigation supports stack operations on all platforms; navigating without wrapping the root page in a NavigationPage; shared code that worked on Android (which has a global navigation host) but fails on iOS.","solutions":["Wrap the page in a NavigationPage: new NavigationPage(rootPage).","Use the NavigationPage's Navigation property for stack operations.","Refactor shared navigation code to target NavigationPage on iOS."],"exampleFix":"// before\nApplication.Current.MainPage.Navigation.InsertPageBefore(page, current);\n// after\nvar nav = new NavigationPage(rootPage);\n// (set as MainPage, then call) nav.Navigation.InsertPageBefore(page, current);","handlingStrategy":"validation","validationCode":"// Ensure root is NavigationPage before stack operations:\nif (!(Application.Current.MainPage is NavigationPage))\n    Application.Current.MainPage = new NavigationPage(Application.Current.MainPage);","typeGuard":"static bool SupportsStackNavigation(Page p) => p is NavigationPage;","tryCatchPattern":null,"preventionTips":["Wrap root in NavigationPage for stack operations on iOS.","Use NavigationPage.Navigation for InsertPageBefore/RemovePage.","Detect iOS in shared code and avoid global navigation stack calls."],"tags":["maui","xamarin-forms","ios","navigation","navigationpage","invalidoperation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}