dotnet/maui · error · ArgumentNullException
before
Error message
before
What it means
InsertPageBefore(page, before) inserts a page before an existing 'before' page. It immediately calls Platform.GetRenderer(before).ViewController (line 575), so 'before' must be non-null and must already have a renderer; the null guard rejects a null 'before' early.
Source
Thrown at src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs:569
}
[PortHandler]
void UpdateUseLargeTitles()
{
if (Forms.IsiOS11OrNewer && NavPage != null)
NavigationBar.PrefersLargeTitles = NavPage.OnThisPlatform().PrefersLargeTitles();
}
[PortHandler]
void UpdateTranslucent()
{
NavigationBar.Translucent = NavPage.OnThisPlatform().IsNavigationBarTranslucent();
}
void InsertPageBefore(Page page, Page before)
{
if (before == null)
throw new ArgumentNullException("before");
if (page == null)
throw new ArgumentNullException("page");
var pageContainer = CreateViewControllerForPage(page);
var target = Platform.GetRenderer(before).ViewController.ParentViewController;
ViewControllers = ViewControllers.Insert(ViewControllers.IndexOf(target), pageContainer);
}
void OnInsertPageBeforeRequested(object sender, NavigationRequestedEventArgs e)
{
InsertPageBefore(e.Page, e.BeforePage);
}
void OnPopRequested(object sender, NavigationRequestedEventArgs e)
{
e.Task = PopViewAsync(e.Page, e.Animated);
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Ensure 'before' is a page currently on the NavigationPage stack and has been pushed/rendered.
- Use NavigationPage.GetPath / inspect Navigation.NavigationStack to confirm the target page exists.
- Null-check 'before' before calling InsertPageBefore.
Example fix
// before
Navigation.InsertPageBefore(newPage, maybeNullPage);
// after
if (Navigation.NavigationStack.Contains(maybeNullPage))
Navigation.InsertPageBefore(newPage, maybeNullPage); Defensive patterns
Strategy: validation
Validate before calling
if (before == null) throw new ArgumentNullException(nameof(before)); if (!Navigation.NavigationStack.Contains(before)) return; Navigation.InsertPageBefore(page, before);
Prevention
- Confirm 'before' is on the stack before inserting.
- Avoid passing stale page references.
When it happens
Trigger: Calling Navigation.InsertPageBefore(page, null) - e.g. the 'before' page reference was not resolved, or a page lookup returned null because the page is not currently on the stack.
Common situations: Inserting before a page that has been popped/removed; passing the wrong page reference; calling InsertPageBefore before the target page is rendered.
Related errors
- page
- InsertPageBefore is not supported globally on Android, pleas
- InsertPageBefore is not supported globally on iOS, please us
- PopAsync is not supported globally on iOS, please use a Navi
- PopToRootAsync is not supported globally on iOS, please use
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/243b6ae4643d2dd3.
Report an issue: GitHub.