{"record":{"id":"f1f066c6a2619fa3","repo":"dotnet/maui","slug":"navigationpage-must-have-a-root-page-before-being-f1f066","errorCode":null,"errorMessage":"NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.","messagePattern":"NavigationPage must have a root Page before being used\\. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs","lineNumber":227,"sourceCode":"\t\t}\n\n\t\tpublic override void ViewDidLoad()\n\t\t{\n\t\t\tbase.ViewDidLoad();\n\n\t\t\tUpdateTranslucent();\n\n\t\t\t_secondaryToolbar = new SecondaryToolbar { Frame = new RectangleF(0, 0, 320, 44) };\n\t\t\tView.Add(_secondaryToolbar);\n\t\t\t_secondaryToolbar.Hidden = true;\n\n\t\t\tFindParentFlyoutPage();\n\n\t\t\tvar navPage = NavPage;\n\t\t\tINavigationPageController navPageController = NavPage;\n\t\t\tif (navPage.CurrentPage == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\n\t\t\t\t\t\"NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.\");\n\t\t\t}\n\n\t\t\tnavPageController.PushRequested += OnPushRequested;\n\t\t\tnavPageController.PopRequested += OnPopRequested;\n\t\t\tnavPageController.PopToRootRequested += OnPopToRootRequested;\n\t\t\tnavPageController.RemovePageRequested += OnRemovedPageRequested;\n\t\t\tnavPageController.InsertPageBeforeRequested += OnInsertPageBeforeRequested;\n\n\t\t\tUpdateBarBackground();\n\t\t\tUpdateBarTextColor();\n\t\t\tUpdateHideNavigationBarSeparator();\n\t\t\tUpdateUseLargeTitles();\n\n\t\t\tif (OperatingSystem.IsIOSVersionAtLeast(11))\n\t\t\t\tSetNeedsUpdateOfHomeIndicatorAutoHidden();\n\n\t\t\t// If there is already stuff on the stack we need to push it","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs#L209-L245","documentation":"In NavigationRenderer.ViewDidLoad, after setting up the toolbar, the renderer checks NavPage.CurrentPage. If null, the NavigationPage has no root page - the iOS navigation controller cannot function without at least one page on its stack, and later code (line 246) iterates NavPageController.Pages and pushes them. So it throws InvalidOperationException with a clear remediation message.","triggerScenarios":"Constructing a NavigationPage with the parameterless constructor and never pushing/adding a page before it is rendered on iOS; or pushing a null page; or removing the last page so the stack becomes empty before ViewDidLoad runs.","commonSituations":"new NavigationPage() with no page passed and no PushAsync before display; binding MainPage to a NavigationPage whose Children is empty initially; removing all pages from the stack while the renderer is loading.","solutions":["Pass a root page to the NavigationPage constructor: new NavigationPage(new RootPage()).","If constructing empty, call PushAsync(rootPage) before the page is shown.","Ensure the NavigationPage is not rendered until at least one child page exists."],"exampleFix":"// before\nMainPage = new NavigationPage(); // no root page\n\n// after\nMainPage = new NavigationPage(new RootPage());","handlingStrategy":"validation","validationCode":"// Before setting MainPage:\nvar nav = new NavigationPage();\nif (nav.CurrentPage == null)\n    nav.PushAsync(new RootPage());\nMainPage = nav;\n// Simplest: pass root in ctor\nMainPage = new NavigationPage(new RootPage());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always seed NavigationPage with a root page in its constructor.","Never remove the last page from a NavigationPage stack."],"tags":["invalidoperationexception","ios","navigationpage","viewdidload","root-page"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}