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 LightNavigationPage.

What it means

IFormsNavigation.RemovePage throws InvalidOperationException stating RemovePage is not supported globally on Windows and instructs to use a LightNavigationPage. The FormsWindow navigation proxy rejects page removal; only a LightNavigationPage supports stack mutation.

Source

Thrown at src/Compatibility/Core/src/WPF/Interfaces/IFormsNavigation.cs:106

		public void Push(object page, bool animated)
		{
			throw new InvalidOperationException("Push is not supported globally on Windows, please use a LightNavigationPage.");
		}

		public void PushModal(object page)
		{
			PushModal(page, true);
		}

		public void PushModal(object page, bool animated)
		{
			ParentWindow?.PushModal(page, animated);
		}

		public void RemovePage(object page)
		{
			throw new InvalidOperationException(
				"RemovePage is not supported globally on Windows, please use a LightNavigationPage.");
		}

		public int StackDepth =>
			throw new InvalidOperationException(
				"StackDepth is not supported globally on Windows, please use a LightNavigationPage.");
	}
}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use a LightNavigationPage and call RemovePage on that instance.
  2. Branch by platform: only remove pages when Navigation is a per-page NavigationPage.
  3. Ensure NavigationProxy resolves to the page-level NavigationPage.
  4. Provide a WPF-specific INavigation implementation if removal is required.

Example fix

// before
Navigation.RemovePage(oldPage);

// after
if (Navigation is LightNavigationPage lnp)
    lnp.RemovePage(oldPage);
Defensive patterns

Strategy: type-guard

Validate before calling

if (Navigation is LightNavigationPage lnp) lnp.RemovePage(page);
else throw new PlatformNotSupportedException("Use LightNavigationPage on WPF.");

Type guard

static bool CanRemove(NavigationProxy n) => n is LightNavigationPage;

Try / catch

try { Navigation.RemovePage(page); }
catch (InvalidOperationException ex) when (ex.Message.Contains("LightNavigationPage"))
{ /* wrap in LightNavigationPage, retry */ }

Prevention

When it happens

Trigger: Calling Navigation.RemovePage(page) against the window-level navigation proxy; removing pages from the global stack instead of a per-page NavigationPage.

Common situations: Cross-platform code removing pages from the back stack; pages not wrapped in a LightNavigationPage.

Related errors


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