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

Thrown by the WPF Platform's INavigation.RemovePage implementation. Removing a page from the navigation stack is unsupported at the global platform level on Windows/WPF. Only NavigationPage maintains the stack from which pages can be removed.

Source

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

		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);
		}

		Task INavigation.PushModalAsync(Page page, bool animated)

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure MainPage is wrapped in a NavigationPage before calling RemovePage.
  2. Cast to NavigationPage and call RemovePage on it directly.
  3. If the intent is to replace the visible page, set MainPage directly instead of using RemovePage.

Example fix

// before
Application.Current.MainPage.Navigation.RemovePage(loginPage);

// after
var navPage = Application.Current.MainPage as NavigationPage;
if (navPage != null)
    navPage.Navigation.RemovePage(loginPage);
Defensive patterns

Strategy: validation

Validate before calling

if (Application.Current.MainPage is NavigationPage navPage)
    navPage.Navigation.RemovePage(page);

Type guard

static bool CanRemovePage(Page root) => root is NavigationPage;

Prevention

When it happens

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

Common situations: Shared code removes a page from the stack after navigation (e.g., removing a login page), but the WPF host was not set up with a NavigationPage.

Related errors


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