PrismLibrary/Prism · error · InvalidOperationException

No current page has been set.

Error message

No current page has been set.

What it means

GetCurrentPage found a valid PrismWindow but its CurrentPage is null - the window exists but Prism has not set/assigned the active page yet (or it was cleared). It throws InvalidOperationException('No current page has been set.') rather than returning null.

Solutions

  1. Move the call to after navigation completes (OnNavigatedTo / NavigationCompleted), not the page constructor.
  2. Create the PrismWindow with an initial page: `new PrismWindow(new NavigationPage().WithNavigationService(...))` per Prism startup docs.
  3. Guard the call: check `prismWindow.CurrentPage` (or CurrentWindow state) before invoking extensions that depend on the current page.

Example fix

// before
public MyPage() { var page = windowManager.GetCurrentPage(); } // CurrentPage not yet set
// after
public void OnNavigatedTo(INavigationParameters p)
{
    var page = windowManager.GetCurrentPage(); // safe now
}
Defensive patterns

Strategy: validation

Validate before calling

if (windowManager.Current is PrismWindow pw && pw.CurrentPage is null)
    throw new InvalidOperationException("CurrentPage not yet set; call after navigation completes");

Type guard

bool HasCurrentPage(IWindowManager wm) => wm.Current is PrismWindow { CurrentPage: not null };

Try / catch

try { var page = windowManager.GetCurrentPage(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("No current page has been set"))
{
    // retry after OnNavigatedTo / navigation completion
}

Prevention

When it happens

Trigger: Calling page-dependent IWindowManager extensions during window construction before the first page finishes navigation; after a window's content is replaced manually without going through Prism navigation; on a freshly created PrismWindow with no content.

Common situations: Calling GetPageScope/GetNavigationService-style extensions inside CreateWindow or a page constructor too early; performing window work on app resume before navigation completes; forcing `new PrismWindow()` without a page and navigating later.

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/29348e602f5619d1. Report an issue: GitHub.

Appendix: source

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

    /// </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)