dotnet/maui · error · InvalidOperationException

RemovePage is not supported globally on Android, please use

Error message

RemovePage is not supported globally on Android, please use a NavigationPage.

What it means

Thrown by the Platform class's explicit INavigation.RemovePage implementation. Removing a page from the back stack is a NavigationPage operation on Android; the global platform only supports modal navigation and therefore rejects RemovePage.

Source

Thrown at src/Compatibility/Core/src/Android/AppCompat/Platform.cs:220

			CurrentPageController?.SendDisappearing();
			UpdateAccessibilityImportance(CurrentPageController as Page, ImportantForAccessibility.NoHideDescendants, false);

			_navModel.PushModal(modal);

			Task presentModal = PresentModal(modal, animated);

			await presentModal;

			UpdateAccessibilityImportance(modal, ImportantForAccessibility.Auto, true);

			// Verify that the modal is still on the stack
			if (_navModel.CurrentPage == modal)
				((IPageController)modal).SendAppearing();
		}

		void INavigation.RemovePage(Page page)
		{
			throw new InvalidOperationException("RemovePage is not supported globally on Android, please use a NavigationPage.");
		}

		public static SizeRequest GetNativeSize(
			IVisualElementRenderer visualElementRenderer,
			double widthConstraint,
			double heightConstraint)
		{
			var context = visualElementRenderer.View.Context;

			// negative numbers have special meanings to android they don't to us
			widthConstraint = widthConstraint <= -1 ? double.PositiveInfinity : context.ToPixels(widthConstraint);
			heightConstraint = heightConstraint <= -1 ? double.PositiveInfinity : context.ToPixels(heightConstraint);

			bool widthConstrained = !double.IsPositiveInfinity(widthConstraint);
			bool heightConstrained = !double.IsPositiveInfinity(heightConstraint);

			int widthMeasureSpec = widthConstrained
							? MeasureSpecFactory.MakeMeasureSpec((int)widthConstraint, MeasureSpecMode.AtMost)

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use a NavigationPage as the root so RemovePage is handled by the NavigationPage renderer.
  2. For modal-based flows, pop the modal instead of removing it from a stack.
  3. Restructure the navigation graph so the page you want to remove is part of a NavigationPage's stack.

Example fix

// before
Application.Current.MainPage = new LoginPage();
// after login
Application.Current.MainPage.Navigation.RemovePage(loginPage); // throws

// after
Application.Current.MainPage = new NavigationPage(new LoginPage());
Application.Current.MainPage.Navigation.RemovePage(loginPage);
Defensive patterns

Strategy: validation

Validate before calling

// Only RemovePage when inside a NavigationPage.
var np = NavigationPage.GetNavigationPage(currentPage);
if (np != null)
    np.Navigation.RemovePage(pageToRemove);
else
    await currentPage.Navigation.PopModalAsync();

Prevention

When it happens

Trigger: Calling Application.Current.MainPage.Navigation.RemovePage(page) on Android when MainPage is not a NavigationPage. Often hit when trying to clean up the navigation stack after a login flow.

Common situations: Post-login flow that removes the login page from the stack without a NavigationPage host. Shared code calling RemovePage that works on iOS but fails on Android.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/bcccacb61e0dc740. Report an issue: GitHub.