{"record":{"id":"9cb2515589d83859","repo":"dotnet/maui","slug":"insertpagebefore-is-not-supported-globally-on-wind-9cb251","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/WPF/Platform.cs","lineNumber":218,"sourceCode":"\n\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(\"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(\"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\n\t\t\tvar tcs = new TaskCompletionSource<bool>();","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Platform.cs#L200-L236","documentation":"Thrown by the WPF Platform's INavigation.InsertPageBefore implementation. Inserting a page before another in the navigation stack is unsupported at the global platform level on Windows/WPF. This operation requires a NavigationPage to manage the ordered page list.","triggerScenarios":"Calling Application.Current.MainPage.Navigation.InsertPageBefore(page, before) when MainPage is not a NavigationPage.","commonSituations":"Shared code inserts a page before an existing one (e.g., inserting a wizard step), but the WPF root was not set up as a NavigationPage.","solutions":["Wrap the root page in a NavigationPage so InsertPageBefore has a stack to operate on.","Call InsertPageBefore on a NavigationPage reference directly.","If only reordering the root, set MainPage to the desired page directly."],"exampleFix":"// before\nApplication.Current.MainPage.Navigation.InsertPageBefore(new Step1Page(), existingPage);\n\n// after\nApplication.Current.MainPage = new NavigationPage(new RootPage());\nApplication.Current.MainPage.Navigation.InsertPageBefore(new Step1Page(), existingPage);","handlingStrategy":"validation","validationCode":"if (Application.Current.MainPage is NavigationPage navPage)\n    navPage.Navigation.InsertPageBefore(page, before);","typeGuard":"static bool CanInsertPage(Page root) => root is NavigationPage;","tryCatchPattern":null,"preventionTips":["Ensure a NavigationPage host exists before InsertPageBefore.","Validate the page type in shared navigation code."],"tags":["wpf","maui-compatibility","navigation","navigationpage","platform"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}