PrismLibrary/Prism · error · NullReferenceException
The Page is null.
Error message
The Page is null.
What it means
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.
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.
Example fix
// before
await _navigationService.SelectTabAsync("TabB");
// after
if (_pageAccessor.Page?.GetParentPage() is TabbedPage)
await _navigationService.SelectTabAsync("TabB");
else
await _navigationService.NavigateAsync("TabbedPage?selected=TabB"); Defensive patterns
Strategy: type-guard
Validate before calling
var current = _pageAccessor.Page; bool inTabbedPage = current is not null && current.Parent is TabbedPage || current?.Parent?.Parent is TabbedPage; if (inTabbedPage) await _navigationService.SelectTabAsync(tabName);
Type guard
bool IsInsideTabbedPage(Page p) =>
p?.GetParentPage() is TabbedPage; Try / catch
try { await _navigationService.SelectTabAsync(tabName); }
catch (NullReferenceException) { /* current page is not a TabbedPage child; fallback navigation */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid Tab Name
- No Tab found with the Name
- The builder does not implement IRegistryAware
- NavigationException.NoPageIsRegistered
- configureSegment
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/6c7ed4aceb875f31.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/PageNavigationService.cs:374
try
{
ArgumentException.ThrowIfNullOrWhiteSpace(tabName);
await PageNavigationService.WaitForPendingNavigationRequests();
NavigationSource = PageNavigationSource.NavigationService;
var tabbedPage = GetTabbedPage(_pageAccessor.Page);
static TabbedPage GetTabbedPage(Element page) =>
page switch
{
TabbedPage tabbedPage => tabbedPage,
null => null,
_ => GetTabbedPage(page.Parent)
};
if (tabbedPage is null)
throw new NullReferenceException("The Page is null.");
var parts = tabName.Split('|');
Page selectedChild = null;
if (parts.Length == 1)
{
var tabRegistration = Registry.Registrations.FirstOrDefault(x => x.Name == tabName);
selectedChild = tabbedPage.Children.FirstOrDefault(x =>
ViewModelLocator.GetNavigationName(x) == tabName
|| (x is NavigationPage navPage && ViewModelLocator.GetNavigationName(navPage.RootPage) == tabName)
|| (tabRegistration is not null && x is NavigationPage np && IsPage(np.RootPage, tabRegistration, tabName))
|| (tabRegistration is not null && IsPage(x, tabRegistration, tabName)));
}
else if (parts.Length == 2)
{
var rootRegistration = Registry.Registrations.FirstOrDefault(x => x.Name == parts[0]);
var leafRegistration = Registry.Registrations.FirstOrDefault(x => x.Name == parts[1]);
selectedChild = tabbedPage.Children.FirstOrDefault(x =>
x is NavigationPage navPageView on GitHub (pinned to 358118cd64)