dotnet/maui · error · InvalidOperationException
RemovePage is not supported globally on Windows, please use
Error message
RemovePage is not supported globally on Windows, please use a NavigationPage.
What it means
The Windows Platform class's explicit INavigation.RemovePage throws unconditionally. Removing a specific page from the navigation stack (without popping) is only supported through a NavigationPage host on Windows.
Source
Thrown at src/Compatibility/Core/src/Windows/Platform.cs:228
Task INavigation.PushAsync(Page root, bool animated)
{
throw new InvalidOperationException("PushAsync is not supported globally on Windows, please use a NavigationPage.");
}
Task<Page> INavigation.PopAsync(bool animated)
{
throw new InvalidOperationException("PopAsync is not supported globally on Windows, please use a NavigationPage.");
}
Task INavigation.PopToRootAsync(bool animated)
{
throw new InvalidOperationException(
"PopToRootAsync is not supported globally on Windows, please use a NavigationPage.");
}
void INavigation.RemovePage(Page page)
{
throw new InvalidOperationException("RemovePage is not supported globally on Windows, please use a NavigationPage.");
}
void INavigation.InsertPageBefore(Page page, Page before)
{
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);
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Use NavigationPage as root so RemovePage delegates to its stack management
- Replace the MainPage entirely instead of removing a page from the stack
- Guard the call: if (Device.RuntimePlatform == Device.WinUI) { MainPage = newPage; } else { Navigation.RemovePage(page); }
Example fix
// before MainPage = new MyContentPage(); Navigation.RemovePage(loginPage); // throws // after MainPage = new NavigationPage(new MyContentPage()); Navigation.RemovePage(loginPage); // works
Defensive patterns
Strategy: validation
Validate before calling
// Before calling RemovePage, verify NavigationPage
if (Application.Current.MainPage is NavigationPage navPage)
{
navPage.Navigation.RemovePage(targetPage);
}
else
{
// Windows: replace MainPage directly
Application.Current.MainPage = newPage;
} Type guard
static bool SupportsRemovePage()
{
return Application.Current.MainPage is NavigationPage;
} Prevention
- Use NavigationPage so RemovePage delegates to the internal stack
- For login-removal patterns, consider replacing MainPage directly on Windows
- Abstract stack manipulation behind a navigation service
When it happens
Trigger: Calling Application.Current.MainPage.Navigation.RemovePage(page) when MainPage is not a NavigationPage. Common in post-login flows where the login page is removed from the stack.
Common situations: Removing a login or wizard page from the back stack; shared code that calls RemovePage across all platforms without Windows-specific handling.
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
- InsertPageBefore is not supported globally on Windows, pleas
- Could not find or create a renderer for {visualElement}
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/b45088b0241d2067.
Report an issue: GitHub.