PrismLibrary/Prism · error · InvalidOperationException

No Window has been set in the Application

Error message

No Window has been set in the Application

What it means

The internal GetCurrentPage extension on IWindowManager reads windowManager.Current; if no window has been activated/registered with Prism yet, it throws InvalidOperationException('No Window has been set in the Application'). It exists so page-related helper extensions can fail loudly instead of returning a null Page.

Solutions

  1. Defer the call until after a Prism window exists (e.g. inside OnCreated/OnNavigatedTo of the first page, not App startup).
  2. Ensure App.CreateWindow is overridden per Prism docs (returning a PrismWindow) so the WindowManager gets a Current window.
  3. If you only need the service, resolve IWindowManager only after window creation, or guard with `windowManager.Current is null` checks.

Example fix

// before
public App() { var page = windowManager.GetCurrentPage(); } // no window yet
// after
protected override Window CreateWindow(IActivationState s)
    => new PrismWindow(new NavigationPage(...));
// then in page lifecycle:
OnNavigatedTo(...) => windowManager.GetCurrentPage(); // safe
Defensive patterns

Strategy: validation

Validate before calling

if (windowManager.Current is null)
    throw new InvalidOperationException("Call after Prism has created the application window");

Type guard

bool HasActiveWindow(IWindowManager wm) => wm.Current is not null;

Try / catch

try { var page = windowManager.GetCurrentPage(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("No Window has been set"))
{
    // defer work until after window creation
}

Prevention

When it happens

Trigger: Calling an IWindowManager extension that relies on GetCurrentPage (e.g. GetNavigationService/GetPageScope helpers) before CreateWindow has run, or after the application's windows were cleared/closed.

Common situations: Accessing page/window services in App constructor or OnStartup before window creation; calling extensions from a background thread very early in launch; MAUI apps that override window creation and never register the window with Prism's WindowManager.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/f69306107cad7803. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs:38

    }

    /// <summary>
    /// Gets the <see cref="IDialogService"/> for the currently displayed <see cref="Page"/>.
    /// </summary>
    /// <param name="windowManager">The <see cref="IWindowManager"/>.</param>
    /// <returns>The <see cref="IDialogService"/> for the current <see cref="Page"/>.</returns>
    public static IDialogService GetCurrentDialogService(this IWindowManager windowManager)
    {
        var page = windowManager.GetCurrentPage();
        var container = page.GetContainerProvider();
        return container.Resolve<IDialogService>();
    }

    private static Page GetCurrentPage(this IWindowManager windowManager)
    {
        var window = windowManager.Current;
        if (window is null)
            throw new InvalidOperationException("No Window has been set in the Application");
        else if (window is not PrismWindow prismWindow)
            throw new InvalidOperationException($"Prism applications only support the use of PrismWindow, but found '{window.GetType().FullName}'.");
        else if (prismWindow.CurrentPage is null)
            throw new InvalidOperationException("No current page has been set.");
        else
            return prismWindow.CurrentPage;
    }
}

View on GitHub (pinned to 358118cd64)