{"record":{"id":"cba65f1bc6fcf42d","repo":"dotnet/maui","slug":"removepage-is-not-supported-globally-on-macos-ple","errorCode":null,"errorMessage":"RemovePage is not supported globally on macOS, please use a NavigationPage.","messagePattern":"RemovePage is not supported globally on macOS, please use a NavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/MacOS/PlatformNavigation.cs","lineNumber":85,"sourceCode":"\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 modal, bool animated)\n\t\t{\n\t\t\treturn _modalTracker.PushAsync(modal, _animateModals && animated);\n\t\t}\n\n\t\tTask<Page> INavigation.PopModalAsync(bool animated)\n\t\t{\n\t\t\treturn _modalTracker.PopAsync(animated);\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 macOS, 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 macOS, please use a NavigationPage.\");\n\t\t}\n\n\t\tprotected virtual void Dispose(bool disposing)\n\t\t{\n\t\t\tif (!_disposed)\n\t\t\t{\n\t\t\t\tif (disposing)\n\t\t\t\t{\n\t\t\t\t\t_modalTracker.Dispose();\n\t\t\t\t\t_modalTracker = null;\n\t\t\t\t\t_platformRenderer = null;\n\t\t\t\t}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/MacOS/PlatformNavigation.cs#L67-L103","documentation":"RemovePage (removing a page from the middle of a stack) is a stack-level operation; the macOS global Platform has no page stack, so PlatformNavigation throws InvalidOperationException. Removal must go through a NavigationPage that owns the stack being edited.","triggerScenarios":"Calling Navigation.RemovePage(page) when Navigation points at the global macOS Platform — MainPage is not a NavigationPage, so there is no stack to remove from.","commonSituations":"Login/wizard flows that remove intermediate pages via Navigation.RemovePage. Shared navigation utilities assuming a global stack. Logout cleanup code.","solutions":["Host pages in a NavigationPage (MainPage = new NavigationPage(root)) and call RemovePage on a page within it.","Re-architect the flow to use modal push/pop if a NavigationPage isn't suitable on macOS.","Guard RemovePage so it only runs when a NavigationPage ancestor is present."],"exampleFix":"// before\nMainPage = new ContentPage();\nNavigation.RemovePage(loginPage); // throws on macOS\n\n// after\nMainPage = new NavigationPage(loginPage);\nawait Navigation.PushAsync(home);\nNavigation.RemovePage(loginPage);","handlingStrategy":"validation","validationCode":"if (page.Parent is NavigationPage np && np.Navigation.NavigationStack.Contains(target))\n    Navigation.RemovePage(target);","typeGuard":"static bool CanRemovePage(Page target) => target?.Parent is NavigationPage;","tryCatchPattern":null,"preventionTips":["Only RemovePage against a NavigationPage-owned stack.","Confirm the target is on the stack before removing.","Keep wizard/login flows inside a NavigationPage."],"tags":["macos","navigation","navigationpage","platform-limitation","maui","xamarin"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}