dotnet/maui · error · InvalidOperationException

RemovePage is not supported globally on iOS, please use a Na

Error message

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

What it means

Platform.cs throws InvalidOperationException for INavigation.RemovePage. Removing a page from the global stack is not supported on iOS; only a NavigationPage-managed stack allows RemovePage operations.

Source

Thrown at src/Compatibility/Core/src/iOS/Platform.cs:213

				if (presentationStyle == UIKit.UIModalPresentationStyle.FullScreen)
					shouldFire = false; // This is mainly for backwards compatibility
			}

			if (_appeared && shouldFire)
				Page.GetCurrentPage()?.SendDisappearing();

			_modals.Add(modal);

			modal.DescendantRemoved += HandleChildRemoved;

			if (_appeared)
				return PresentModal(modal, _animateModals && animated);
			return Task.FromResult<object>(null);
		}

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

		public static SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
		{
			Performance.Start(out string reference);

			var renderView = GetRenderer(view);
			if (renderView == null || renderView.NativeView == null)
			{
				if (view is IView iView)
				{
					Application.Current?.FindMauiContext()?.CreateLogger<Platform>()?.LogWarning(
						"Someone called Platform.GetNativeSize instead of going through the Handler.");

					return new SizeRequest(iView.Handler.GetDesiredSize(widthConstraint, heightConstraint));
				}

				Performance.Stop(reference);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use NavigationPage and call RemovePage on its Navigation property.
  2. For login flows on iOS, rebuild the NavigationPage root rather than removing individual pages.
  3. Refactor shared code to detect iOS and use NavigationPage semantics.

Example fix

// before
Application.Current.MainPage.Navigation.RemovePage(loginPage);
// after
// MainPage is NavigationPage
Application.Current.MainPage.Navigation.RemovePage(loginPage);
Defensive patterns

Strategy: validation

Validate before calling

if (!(Application.Current.MainPage is NavigationPage))
    Application.Current.MainPage = new NavigationPage(Application.Current.MainPage);
Application.Current.MainPage.Navigation.RemovePage(page);

Type guard

static bool SupportsStackNavigation(Page p) => p is NavigationPage;

Prevention

When it happens

Trigger: Calling MainPage.Navigation.RemovePage(page) when MainPage is not a NavigationPage.

Common situations: Shared code that manipulates the navigation stack from the global interface; switching the root away from NavigationPage while keeping RemovePage calls; cleaner-stack patterns after login flows without a NavigationPage.

Related errors


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