PrismLibrary/Prism · error · NotSupportedException

The current window ' ' is not a PrismWindow.

Error message

The current window '{_windowManager.Current.GetType().FullName}' is not a PrismWindow.

What it means

SingletonDialogService requires the current window to be a PrismWindow, because PrismWindow tracks CurrentPage for dialog placement. If IWindowManager.Current is some other Window subclass (a plain Microsoft.Maui.Controls.Window or custom window), Prism throws NotSupportedException naming the actual type.

Solutions

  1. Let Prism create the window (remove the CreateWindow override) so a PrismWindow is used.
  2. If you must create the window, make your custom window derive from PrismWindow.
  3. Ensure startup uses PrismAppBuilder (UsePrismAppNaming / PrismApplication) rather than raw MauiApplication window setup.

Example fix

// before
protected override Window CreateWindow(IActivationState state)
    => new Window(new MainPage());
// after
protected override Window CreateWindow(IActivationState state)
    => new PrismWindow(new MainPage()); // or delete the override entirely
Defensive patterns

Strategy: type-guard

Validate before calling

var window = Application.Current?.Windows?.FirstOrDefault();
if (window is not PrismWindow)
    throw new InvalidOperationException("App window must be a PrismWindow for dialogs");

Type guard

bool IsPrismWindow(IWindow w) => w is PrismWindow;

Try / catch

try { await dialogService.ShowDialogAsync(name); }
catch (NotSupportedException ex) when (ex.Message.Contains("PrismWindow"))
{ logger.Error(ex, "Current window is not a PrismWindow"); }

Prevention

When it happens

Trigger: Creating the app's Window as `new Window(mainPage)` or a custom Window subclass instead of PrismWindow — e.g. overriding CreateWindow in App to return a non-Prism window, then calling dialog APIs.

Common situations: Customizing window creation in App.CreateWindow for multi-window or splash scenarios and losing PrismWindow; upgrading Prism.Maui and replacing the default window factory; mixing plain MAUI window management with Prism dialogs.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Dialogs/SingletonDialogService.cs:35

    private readonly IWindowManager _windowManager;

    /// <summary>
    /// Initializes a new SingletonDialogService
    /// </summary>
    /// <param name="windowManager">An instance of the <see cref="IWindowManager"/>.</param>
    public SingletonDialogService(IWindowManager windowManager)
    {
        ArgumentNullException.ThrowIfNull(windowManager);
        _windowManager = windowManager;
    }

    /// <inheritdoc/>
    protected override Page? GetCurrentPage()
    {
        if (_windowManager.Current is null)
            throw new NotSupportedException("There is currently no application window.");
        else if (_windowManager.Current is not PrismWindow prismWindow)
            throw new NotSupportedException($"The current window '{_windowManager.Current.GetType().FullName}' is not a PrismWindow.");
        else
            return prismWindow.CurrentPage;
    }
}

View on GitHub (pinned to 358118cd64)