dotnet/maui · error · ArgumentNullException
page
Error message
page
What it means
PushModalAsync on the Windows Platform INavigation throws ArgumentNullException when the page parameter is null. The guard is a simple null check before adding the page to the navigation model via _navModel.PushModal.
Source
Thrown at src/Compatibility/Core/src/Windows/Platform.cs:250
{
throw new InvalidOperationException(
"InsertPageBefore is not supported globally on Windows, please use a NavigationPage.");
}
Task INavigation.PushModalAsync(Page page)
{
return ((INavigation)this).PushModalAsync(page, true);
}
Task<Page> INavigation.PopModalAsync()
{
return ((INavigation)this).PopModalAsync(true);
}
Task INavigation.PushModalAsync(Page page, bool animated)
{
if (page == null)
throw new ArgumentNullException(nameof(page));
var tcs = new TaskCompletionSource<bool>();
_navModel.PushModal(page);
SetCurrent(page, false, true, () => tcs.SetResult(true));
return tcs.Task;
}
Task<Page> INavigation.PopModalAsync(bool animated)
{
var tcs = new TaskCompletionSource<Page>();
Page result = _navModel.PopModal();
SetCurrent(_navModel.CurrentPage, true, true, () => tcs.SetResult(result));
return tcs.Task;
}
public static SizeRequest GetNativeSize(VisualElement element, double widthConstraint, double heightConstraint)
{
// Hack around the fact that Canvas ignores the child constraints.View on GitHub (pinned to f377ff1c5e)
Solutions
- Null-check the page before calling PushModalAsync
- Ensure the page factory or resolver always returns a valid Page instance
- Use a guard clause: if (page == null) return;
Example fix
// before
await Navigation.PushModalAsync(resolvedPage); // throws if resolvedPage is null
// after
if (resolvedPage == null)
throw new InvalidOperationException("Page could not be resolved");
await Navigation.PushModalAsync(resolvedPage); Defensive patterns
Strategy: validation
Validate before calling
// Before calling PushModalAsync, null-check the page
if (page == null)
throw new ArgumentNullException(nameof(page), "Cannot push a null page modally");
await Navigation.PushModalAsync(page); Prevention
- Always null-check page references before navigation calls
- Ensure page factories/resolvers return valid instances or throw early
- Use guard clauses at the top of navigation methods
When it happens
Trigger: Calling Navigation.PushModalAsync(null) or passing a variable that evaluates to null at runtime, such as a factory method result or a deserialized page reference.
Common situations: Page factory or resolver returns null under certain conditions; conditional page construction where the page wasn't created; navigation parameter binding resolves to null.
Related errors
- PushAsync is not supported globally on Windows, please use a
- PopAsync is not supported globally on Windows, please use a
- PopToRootAsync is not supported globally on Windows, please
- RemovePage is not supported globally on Windows, please use
- InsertPageBefore is not supported globally on Windows, pleas
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e421ab1c4a4637fd.
Report an issue: GitHub.