{"record":{"id":"6945b1949f84decd","repo":"dotnet/maui","slug":"navigationpage-must-have-a-root-page-before-being-6945b1","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":"error","filePath":"src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs","lineNumber":171,"sourceCode":"\n\t\t\treturn new SizeRequest(result);\n\t\t}\n\n\t\tUIElement IVisualElementRenderer.GetNativeElement()\n\t\t{\n\t\t\treturn null;\n\t\t}\n\n\t\tpublic void SetElement(VisualElement element)\n\t\t{\n\t\t\tif (element != null && !(element is NavigationPage))\n\t\t\t\tthrow new ArgumentException(\"Element must be a Page\", nameof(element));\n\n\t\t\tNavigationPage oldElement = Element;\n\t\t\tElement = (NavigationPage)element;\n\n\t\t\tif (Element != null && Element.CurrentPage is null)\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\n\t\t\tif (oldElement is INavigationPageController navigationPageController)\n\t\t\t{\n\t\t\t\tnavigationPageController.PushRequested -= OnPushRequested;\n\t\t\t\tnavigationPageController.PopRequested -= OnPopRequested;\n\t\t\t\tnavigationPageController.PopToRootRequested -= OnPopToRootRequested;\n\t\t\t\toldElement.InternalChildren.CollectionChanged -= OnChildrenChanged;\n\t\t\t\toldElement.PropertyChanged -= OnElementPropertyChanged;\n\t\t\t}\n\n\t\t\tif (element != null)\n\t\t\t{\n\t\t\t\tif (_container == null)\n\t\t\t\t{\n\t\t\t\t\t_container = new PageControl();\n\t\t\t\t\t_container.PointerPressed += OnPointerPressed;\n\t\t\t\t\t_container.SizeChanged += OnNativeSizeChanged;","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs#L153-L189","documentation":"Thrown as InvalidOperationException by NavigationPageRenderer.SetElement when the NavigationPage's CurrentPage is null. A NavigationPage must have at least one page (the root) on its internal stack before it can be rendered. This is enforced because the renderer immediately reads Element.CurrentPage to set up the native container.","triggerScenarios":"Creating a NavigationPage with the default constructor (no root page) and then passing it to the renderer, or calling PushAsync after the renderer is already attached but before any page was pushed.","commonSituations":"Using `new NavigationPage()` without passing a root Page in the constructor, or data-binding a NavigationPage that hasn't had PushAsync called yet.","solutions":["Pass a root Page to the NavigationPage constructor: new NavigationPage(new RootPage()).","Call NavigationPage.PushAsync(rootPage) before the renderer attaches if using the parameterless constructor.","Ensure any data-bound NavigationPage has CurrentPage set before binding completes."],"exampleFix":"// before\nvar navPage = new NavigationPage(); // no root page\nMainPage = navPage; // throws in renderer\n\n// after\nvar navPage = new NavigationPage(new RootPage());\nMainPage = navPage;","handlingStrategy":"validation","validationCode":"var navPage = new NavigationPage();\nif (navPage.CurrentPage == null)\n    navPage.PushAsync(new RootPage());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a root page to the NavigationPage constructor.","Verify NavigationPage.CurrentPage is non-null before assigning it to MainPage."],"tags":["wpf","maui-compatibility","navigationpage","renderer","state-validation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}