{"record":{"id":"b45088b0241d2067","repo":"dotnet/maui","slug":"removepage-is-not-supported-globally-on-windows-p-b45088","errorCode":null,"errorMessage":"RemovePage is not supported globally on Windows, please use a NavigationPage.","messagePattern":"RemovePage 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":228,"sourceCode":"\t\tTask INavigation.PushAsync(Page root, bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"PushAsync is not supported globally on Windows, please use a NavigationPage.\");\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 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","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Windows/Platform.cs#L210-L246","documentation":"The Windows Platform class's explicit INavigation.RemovePage throws unconditionally. Removing a specific page from the navigation stack (without popping) is only supported through a NavigationPage host on Windows.","triggerScenarios":"Calling Application.Current.MainPage.Navigation.RemovePage(page) when MainPage is not a NavigationPage. Common in post-login flows where the login page is removed from the stack.","commonSituations":"Removing a login or wizard page from the back stack; shared code that calls RemovePage across all platforms without Windows-specific handling.","solutions":["Use NavigationPage as root so RemovePage delegates to its stack management","Replace the MainPage entirely instead of removing a page from the stack","Guard the call: if (Device.RuntimePlatform == Device.WinUI) { MainPage = newPage; } else { Navigation.RemovePage(page); }"],"exampleFix":"// before\nMainPage = new MyContentPage();\nNavigation.RemovePage(loginPage); // throws\n\n// after\nMainPage = new NavigationPage(new MyContentPage());\nNavigation.RemovePage(loginPage); // works","handlingStrategy":"validation","validationCode":"// Before calling RemovePage, verify NavigationPage\nif (Application.Current.MainPage is NavigationPage navPage)\n{\n    navPage.Navigation.RemovePage(targetPage);\n}\nelse\n{\n    // Windows: replace MainPage directly\n    Application.Current.MainPage = newPage;\n}","typeGuard":"static bool SupportsRemovePage()\n{\n    return Application.Current.MainPage is NavigationPage;\n}","tryCatchPattern":null,"preventionTips":["Use NavigationPage so RemovePage delegates to the internal stack","For login-removal patterns, consider replacing MainPage directly on Windows","Abstract stack manipulation behind a navigation service"],"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"}