dotnet/maui · critical · NotImplementedException

Either set {nameof(MainPage)} or override {nameof(Applicatio

Error message

Either set {nameof(MainPage)} or override {nameof(Application.CreateWindow)}.

What it means

Thrown by the default Application.CreateWindow when it cannot produce a Window: no IWindowCreator service is registered, more than one Window already exists (ambiguous), and neither MainPage nor a CreateWindow override supplies a page. The default implementation can only fall back to MainPage, so without it the app cannot create its first window.

Source

Thrown at src/Controls/src/Core/Application/Application.cs:579

		{
			Handler?.Invoke(nameof(IApplication.ActivateWindow), window);
		}

		void IApplication.ThemeChanged()
		{
			PlatformAppTheme = AppInfo.RequestedTheme;
		}

		protected virtual Window CreateWindow(IActivationState? activationState)
		{
			var windowCreator = activationState?.Context.Services.GetService<IWindowCreator>();
			var window = windowCreator?.CreateWindow(this, activationState);
			if (window is not null)
				return window;

			if (Windows.Count > 1)
#pragma warning disable CS0618 // Type or member is obsolete
				throw new NotImplementedException($"Either set {nameof(MainPage)} or override {nameof(Application.CreateWindow)}.");
#pragma warning restore CS0618 // Type or member is obsolete

			if (Windows.Count > 0)
				return Windows[0];

			if (_singleWindowMainPage is not null)
				return new Window(_singleWindowMainPage);

#pragma warning disable CS0618 // Type or member is obsolete
			throw new NotImplementedException($"Either set {nameof(MainPage)} or override {nameof(Application.CreateWindow)}.");
#pragma warning restore CS0618 // Type or member is obsolete
		}

		internal void AddWindow(Window window)
		{
			_windows.Add(window);

			if (window is Element windowElement)

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Set Application.MainPage in the App constructor (e.g. MainPage = new AppShell()).
  2. Override protected virtual Window CreateWindow(IActivationState) in your Application subclass and return a Window built from your page/shell.
  3. Register an IWindowCreator via the host builder (builder.UseMauiApp...) if you want framework-driven window creation.

Example fix

// before
public App() { /* nothing set */ }
// after
public App() { MainPage = new AppShell(); }
Defensive patterns

Strategy: validation

Validate before calling

// In your App, guarantee a Window source exists.
public App()
{
    if (Windows.Count == 0)
        MainPage = new AppShell(); // or override CreateWindow
}

Prevention

When it happens

Trigger: CreateWindow is reached with a null windowCreator (no IWindowCreator service), Windows.Count > 1, and no override, so the first NotImplementedException 'Either set MainPage or override CreateWindow' fires.

Common situations: Fresh MAUI app where the developer removed the MainPage assignment but has not yet overridden CreateWindow; misconfigured host builder that did not register IWindowCreator; multi-window experiment left Windows.Count > 1 unexpectedly.

Related errors


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