{"record":{"id":"c121d01ecbab8adc","repo":"dotnet/maui","slug":"insertpagebefore-is-not-supported-globally-on-maco","errorCode":null,"errorMessage":"InsertPageBefore is not supported globally on macOS, please use a NavigationPage.","messagePattern":"InsertPageBefore 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":90,"sourceCode":"\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}\n\n\t\t\t\t_disposed = true;\n\t\t\t}\n\t\t}\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/MacOS/PlatformNavigation.cs#L72-L108","documentation":"InsertPageBefore inserts a page before another in the navigation stack; the macOS global Platform has no page stack, so PlatformNavigation throws InvalidOperationException. Insertion requires a NavigationPage whose renderer owns the stack. This is the last of the global-stack-op limitations on macOS.","triggerScenarios":"Calling Navigation.InsertPageBefore(page, before) when Navigation resolves to the global macOS Platform — MainPage is not a NavigationPage, so there is no stack to insert into.","commonSituations":"Navigation reshaping code (e.g. inserting a page before the current one) shared across platforms. Custom routers/Shell interactions hitting the global Platform on macOS. Logout/reset flows that rebuild the stack.","solutions":["Ensure the page is inside a NavigationPage (MainPage = new NavigationPage(root)) and call InsertPageBefore on a page within it.","Re-implement the flow using modal push/pop if a NavigationPage is not appropriate.","Guard the call so InsertPageBefore only runs when a NavigationPage ancestor exists on macOS."],"exampleFix":"// before\nMainPage = new ContentPage();\nNavigation.InsertPageBefore(newPage, current); // throws on macOS\n\n// after\nMainPage = new NavigationPage(new ContentPage());\nNavigation.InsertPageBefore(newPage, current);","handlingStrategy":"validation","validationCode":"if (Navigation.NavigationStack.Contains(before))\n    Navigation.InsertPageBefore(page, before);","typeGuard":"static bool IsOnStack(Page p) => Navigation.NavigationStack.Contains(p);","tryCatchPattern":null,"preventionTips":["Ensure a NavigationPage hosts the stack before inserting.","Verify the anchor page is still present.","Serialize stack mutations to prevent desync."],"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"}