{"record":{"id":"f5701adfc2d319c3","repo":"dotnet/maui","slug":"insertpagebefore-is-not-supported-globally-on-wind","errorCode":null,"errorMessage":"InsertPageBefore is not supported globally on Windows, please use a LightNavigationPage.","messagePattern":"InsertPageBefore is not supported globally on Windows, please use a LightNavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Interfaces/IFormsNavigation.cs","lineNumber":49,"sourceCode":"\n\t\tvoid RemovePage(object page);\n\t}\n\n\tpublic class DefaultNavigation : IFormsNavigation\n\t{\n\t\tpublic FormsWindow ParentWindow\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tif (System.Windows.Application.Current.MainWindow is FormsWindow)\n\t\t\t\t\treturn System.Windows.Application.Current.MainWindow as FormsWindow;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tpublic void InsertPageBefore(object page, object 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 LightNavigationPage.\");\n\t\t}\n\n\t\tpublic void Pop()\n\t\t{\n\t\t\tPop(true);\n\t\t}\n\n\t\tpublic void Pop(bool animated)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"Pop is not supported globally on Windows, please use a LightNavigationPage.\");\n\t\t}\n\n\t\tpublic void PopModal()\n\t\t{\n\t\t\tPopModal(true);\n\t\t}\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Interfaces/IFormsNavigation.cs#L31-L67","documentation":"IFormsNavigation.InsertPageBefore throws InvalidOperationException stating InsertPageBefore is not supported globally on Windows and instructs to use a LightNavigationPage. The global FormsWindow navigation surface deliberately rejects page-stack mutations; only a LightNavigationPage instance supports InsertPageBefore semantics on WPF.","triggerScenarios":"Calling Navigation.InsertPageBefore on the global/window-level navigation proxy returned by the WPF host; mixing global and per-page navigation; routing InsertPageBefore to FormsWindow.ParentWindow instead of a NavigationPage.","commonSituations":"Porting code that uses a single global Navigation to WPF; assuming window-level nav supports the full INavigation contract; not wrapping pages in a LightNavigationPage.","solutions":["Wrap the target page hierarchy in a LightNavigationPage and call InsertPageBefore on that instance instead of the global proxy.","Replace Navigation.InsertPageBefore usages with LightNavigationPage.InsertPageBefore in WPF-specific code paths.","Detect the platform and branch to the LightNavigationPage path for Windows.","Audit NavigationProxy usage to ensure INavigation resolves to a per-page NavigationPage."],"exampleFix":"// before\nNavigation.InsertPageBefore(newPage, current);\n\n// after\nif (Navigation is LightNavigationPage lnp)\n    lnp.InsertPageBefore(newPage, current);\nelse\n    throw new PlatformNotSupportedException(\"Use LightNavigationPage on WPF.\");","handlingStrategy":"type-guard","validationCode":"if (Navigation is LightNavigationPage lnp) lnp.InsertPageBefore(page, before);\nelse throw new PlatformNotSupportedException(\"Use LightNavigationPage on WPF.\");","typeGuard":"static bool SupportsInsert(NavigationProxy n) => n is LightNavigationPage;","tryCatchPattern":"try { Navigation.InsertPageBefore(page, before); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"LightNavigationPage\"))\n{ /* wrap in LightNavigationPage then retry */ }","preventionTips":["Wrap pages in a LightNavigationPage at construction on WPF.","Branch navigation by platform or by Navigation type.","Provide a WPF-specific INavigation implementation."],"tags":["wpf","navigation","not-supported","light-navigation-page"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}