dotnet/maui · error · InvalidOperationException

PopToRootAsync is not supported globally on Windows, please

Error message

PopToRootAsync is not supported globally on Windows, please use a NavigationPage.

What it means

The Windows Platform class's explicit INavigation.PopToRootAsync(bool) throws unconditionally. Clearing the navigation stack back to root is only supported through a NavigationPage host, not the global Platform navigation context on Windows.

Source

Thrown at src/Compatibility/Core/src/Windows/Platform.cs:222

		Task INavigation.PopToRootAsync()
		{
			return ((INavigation)this).PopToRootAsync(true);
		}

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

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Use NavigationPage as the root container so PopToRootAsync operates on its internal stack
  2. Manually reset MainPage to the root page instead of using PopToRootAsync
  3. Branch navigation calls per-platform using OnPlatform or Device.RuntimePlatform

Example fix

// before
MainPage = new MyContentPage();
await MainPage.Navigation.PopToRootAsync(); // throws

// after
MainPage = new NavigationPage(new MyContentPage());
await MainPage.Navigation.PopToRootAsync(); // works
Defensive patterns

Strategy: validation

Validate before calling

// Before calling PopToRootAsync, verify NavigationPage
if (Application.Current.MainPage is NavigationPage navPage && navPage.Navigation.NavigationStack.Count > 1)
{
    await navPage.Navigation.PopToRootAsync();
}

Type guard

static bool HasNavigationStack()
{
    return Application.Current.MainPage is NavigationPage nav
        && nav.Navigation.NavigationStack.Count > 1;
}

Prevention

When it happens

Trigger: Calling Application.Current.MainPage.Navigation.PopToRootAsync() when MainPage is not a NavigationPage. The global Platform INavigation rejects the operation.

Common situations: Shared code calling PopToRootAsync after deep linking or logout flow; cross-platform navigation abstraction that doesn't account for Windows limitations.

Related errors


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