dotnet/maui · error · InvalidOperationException

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

Error message

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

What it means

RemovePage (which takes a Page out of the middle of a navigation stack) is a stack-level operation. The global GTK Platform has no page stack — only a modal list — so it cannot remove a page and throws. Removal must be performed by a NavigationPage that owns the stack it is editing.

Source

Thrown at src/Compatibility/Core/src/GTK/Platform.cs:279

						if (page.Children != null)
						{
							foreach (var child in page.Children)
							{
								child.ShowAll();
							}

							page.ShowAll();
						}
					}
				}
			});

			return Task.FromResult<object>(null);
		}

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

		internal class DefaultRenderer : VisualElementRenderer<VisualElement, Widget>
		{

		}
	}
}

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure the page lives inside a NavigationPage (Application.Current.MainPage = new NavigationPage(root)), then call Navigation.RemovePage on a page within that NavigationPage.
  2. Re-implement the flow using modal push/pop if a NavigationPage is not appropriate for GTK.
  3. Guard with a runtime check so RemovePage is only called when a NavigationPage ancestor exists.

Example fix

// before
MainPage = new ContentPage();
Navigation.RemovePage(loginPage); // throws on GTK

// after
MainPage = new NavigationPage(loginPage);
// after login success:
await Navigation.PushAsync(homePage);
Navigation.RemovePage(loginPage);
Defensive patterns

Strategy: validation

Validate before calling

if (page.Parent is NavigationPage np && np.Navigation.NavigationStack.Contains(target))
    Navigation.RemovePage(target);

Type guard

static bool CanRemovePage(Page target) =>
    target?.Parent is NavigationPage;

Prevention

When it happens

Trigger: Calling Navigation.RemovePage(page) when Navigation points at the global GTK Platform: MainPage is not a NavigationPage, so RemovePage has no stack to act on.

Common situations: Login-flow code that removes the login page after success via Navigation.RemovePage. Shared navigation utilities that assume a global stack exists on every backend.

Related errors


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