dotnet/maui · error · InvalidOperationException

NavigationStack is not supported globally on Windows, please

Error message

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

What it means

Thrown by the WPF Platform's INavigation.NavigationStack getter. The global Windows/WPF platform does not maintain a navigation stack — only NavigationPage does. Accessing Application.Current.MainPage.Navigation.NavigationStack without wrapping the root in a NavigationPage triggers this.

Source

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

			self.SetValue(RendererProperty, renderer);
			self.IsPlatformEnabled = renderer != null;
		}

		internal void SetPage(Page newRoot)
		{
			if (newRoot == null)
				return;

			Page = newRoot;

			_page.StartupPage = Page;
			Application.Current.NavigationProxy.Inner = this;
		}


		public IReadOnlyList<Page> NavigationStack
		{
			get { throw new InvalidOperationException("NavigationStack is not supported globally on Windows, please use a NavigationPage."); }
		}

		public IReadOnlyList<Page> ModalStack
		{
			get
			{
				return _page.InternalChildren.Cast<Page>().ToList();
			}
		}

		Task INavigation.PushAsync(Page root)
		{
			return ((INavigation)this).PushAsync(root, true);
		}

		Task<Page> INavigation.PopAsync()
		{
			return ((INavigation)this).PopAsync(true);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Wrap the root page in a NavigationPage: new NavigationPage(new MainPage()).
  2. Access NavigationStack from a NavigationPage instance rather than from the global proxy.
  3. In shared code, check if the current page is a NavigationPage before accessing NavigationStack.

Example fix

// before
var stack = Application.Current.MainPage.Navigation.NavigationStack;

// after
Application.Current.MainPage = new NavigationPage(new MainPage());
var stack = Application.Current.MainPage.Navigation.NavigationStack;
Defensive patterns

Strategy: validation

Validate before calling

if (Application.Current.MainPage is NavigationPage navPage)
    var stack = navPage.Navigation.NavigationStack;

Type guard

static bool HasNavigationStack(Page page) => page is NavigationPage;

Prevention

When it happens

Trigger: Reading NavigationStack from Application.Current.MainPage.Navigation (or the global INavigation proxy) when the MainPage is not a NavigationPage.

Common situations: Calling Application.Current.MainPage.Navigation.NavigationStack in shared code that assumes a stack-based nav host, but the Windows/WPF app was bootstrapped with a plain ContentPage or TabbedPage root.

Related errors


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