{"record":{"id":"65f73e54d8f7dda4","repo":"dotnet/maui","slug":"insertpagebefore-is-not-supported-globally-on-wind-65f73e","errorCode":null,"errorMessage":"InsertPageBefore is not supported globally on Windows, please use a NavigationPage.","messagePattern":"InsertPageBefore is not supported globally on Windows, please use a NavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Windows/Platform.cs","lineNumber":233,"sourceCode":"\t\tTask<Page> INavigation.PopAsync(bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"PopAsync is not supported globally on Windows, please use a NavigationPage.\");\n\t\t}\n\n\t\tTask INavigation.PopToRootAsync(bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\n\t\t\t\t\"PopToRootAsync is not supported globally on Windows, please use a NavigationPage.\");\n\t\t}\n\n\t\tvoid INavigation.RemovePage(Page page)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"RemovePage is not supported globally on Windows, please use a NavigationPage.\");\n\t\t}\n\n\t\tvoid INavigation.InsertPageBefore(Page page, Page before)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\n\t\t\t\t\"InsertPageBefore is not supported globally on Windows, please use a NavigationPage.\");\n\t\t}\n\n\t\tTask INavigation.PushModalAsync(Page page)\n\t\t{\n\t\t\treturn ((INavigation)this).PushModalAsync(page, true);\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 INavigation.PushModalAsync(Page page, bool animated)\n\t\t{\n\t\t\tif (page == null)\n\t\t\t\tthrow new ArgumentNullException(nameof(page));\n","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Windows/Platform.cs#L215-L251","documentation":"The Windows Platform class's explicit INavigation.InsertPageBefore throws unconditionally. Inserting a page before another in the navigation stack is only supported through a NavigationPage host on Windows, not the global Platform navigation context.","triggerScenarios":"Calling Application.Current.MainPage.Navigation.InsertPageBefore(newPage, existingPage) when MainPage is not a NavigationPage. Common in dynamic navigation flows where pages are inserted at specific positions.","commonSituations":"Building dynamic navigation hierarchies; inserting a page before the current root for back-navigation purposes; shared cross-platform code.","solutions":["Use NavigationPage as root so InsertPageBefore operates on its managed stack","Rebuild the navigation stack from scratch rather than inserting mid-stack","Abstract navigation behind a service with platform-specific implementations"],"exampleFix":"// before\nMainPage = new MyContentPage();\nNavigation.InsertPageBefore(newRoot, MainPage); // throws\n\n// after\nMainPage = new NavigationPage(new MyContentPage());\nNavigation.InsertPageBefore(newRoot, currentRoot); // works","handlingStrategy":"validation","validationCode":"// Before calling InsertPageBefore, verify NavigationPage\nif (Application.Current.MainPage is NavigationPage navPage)\n{\n    navPage.Navigation.InsertPageBefore(newPage, existingPage);\n}\nelse\n{\n    // Windows: rebuild navigation from scratch\n    Application.Current.MainPage = new NavigationPage(newPage);\n}","typeGuard":"static bool SupportsInsertPage()\n{\n    return Application.Current.MainPage is NavigationPage;\n}","tryCatchPattern":null,"preventionTips":["Ensure NavigationPage hosts the root before using InsertPageBefore","Consider rebuilding the stack rather than inserting mid-stack on Windows","Test dynamic navigation hierarchy construction on all platforms"],"tags":["navigation","winui","uwp","maui-compatibility","platform-limitation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}