{"record":{"id":"6c7ed4aceb875f31","repo":"PrismLibrary/Prism","slug":"the-page-is-null","errorCode":null,"errorMessage":"The Page is null.","messagePattern":"The Page is null\\.","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/PageNavigationService.cs","lineNumber":374,"sourceCode":"        try\n        {\n            ArgumentException.ThrowIfNullOrWhiteSpace(tabName);\n\n            await PageNavigationService.WaitForPendingNavigationRequests();\n            NavigationSource = PageNavigationSource.NavigationService;\n\n            var tabbedPage = GetTabbedPage(_pageAccessor.Page);\n\n            static TabbedPage GetTabbedPage(Element page) =>\n                page switch\n                {\n                    TabbedPage tabbedPage => tabbedPage,\n                    null => null,\n                    _ => GetTabbedPage(page.Parent)\n                };\n\n            if (tabbedPage is null)\n                throw new NullReferenceException(\"The Page is null.\");\n\n            var parts = tabName.Split('|');\n            Page selectedChild = null;\n            if (parts.Length == 1)\n            {\n                var tabRegistration = Registry.Registrations.FirstOrDefault(x => x.Name == tabName);\n                selectedChild = tabbedPage.Children.FirstOrDefault(x =>\n                    ViewModelLocator.GetNavigationName(x) == tabName\n                    || (x is NavigationPage navPage && ViewModelLocator.GetNavigationName(navPage.RootPage) == tabName)\n                    || (tabRegistration is not null && x is NavigationPage np && IsPage(np.RootPage, tabRegistration, tabName))\n                    || (tabRegistration is not null && IsPage(x, tabRegistration, tabName)));\n            }\n            else if (parts.Length == 2)\n            {\n                var rootRegistration = Registry.Registrations.FirstOrDefault(x => x.Name == parts[0]);\n                var leafRegistration = Registry.Registrations.FirstOrDefault(x => x.Name == parts[1]);\n                selectedChild = tabbedPage.Children.FirstOrDefault(x =>\n                    x is NavigationPage navPage","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs#L356-L392","documentation":"SelectTabAsync must locate the TabbedPage that owns the current page, walking up the Parent chain. If the current page is null or its ancestry contains no TabbedPage, the result is null and the method throws NullReferenceException('The Page is null.') because selecting a tab is only meaningful from within a TabbedPage.","triggerScenarios":"Calling SelectTabAsync when the current page is not a child of a TabbedPage (e.g. a plain ContentPage in a NavigationPage); the page has no Parent yet (not fully attached to the visual tree); calling before any navigation has set the accessor's Page.","commonSituations":"Invoking SelectTab from a ViewModel on a non-tab page after a refactor; calling too early in the page lifecycle (OnAppearing before parent assignment); using the method in a CarouselView/Shell-based layout that isn't a real TabbedPage.","solutions":["Only call SelectTabAsync when the current page is a child of a TabbedPage; check the page/parent type first.","Move the call to after the page is attached (e.g. OnNavigatedTo instead of constructor) so Parent is set.","Verify the navigation structure: wrap the target page in a TabbedPage or use NavigateAsync with the tab URI syntax instead.","Guard the call: resolve the current page and skip tab selection if it isn't a TabbedPage child."],"exampleFix":"// before\nawait _navigationService.SelectTabAsync(\"TabB\");\n// after\nif (_pageAccessor.Page?.GetParentPage() is TabbedPage)\n    await _navigationService.SelectTabAsync(\"TabB\");\nelse\n    await _navigationService.NavigateAsync(\"TabbedPage?selected=TabB\");","handlingStrategy":"type-guard","validationCode":"var current = _pageAccessor.Page;\nbool inTabbedPage = current is not null && current.Parent is TabbedPage || current?.Parent?.Parent is TabbedPage;\nif (inTabbedPage) await _navigationService.SelectTabAsync(tabName);","typeGuard":"bool IsInsideTabbedPage(Page p) =>\n    p?.GetParentPage() is TabbedPage;","tryCatchPattern":"try { await _navigationService.SelectTabAsync(tabName); }\ncatch (NullReferenceException) { /* current page is not a TabbedPage child; fallback navigation */ }","preventionTips":["Call SelectTabAsync only from pages hosted in a TabbedPage","Call after the page is attached to the visual tree (Parent set), e.g. OnNavigatedTo","Use NavigateAsync with the TabbedPage URI for non-tab contexts"],"tags":["navigation","tabbedpage","null-reference","prism","xamarin-maui"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}