PrismLibrary/Prism · error · InvalidOperationException
Prism applications only support the use of PrismWindow, but…
Error message
Prism applications only support the use of PrismWindow, but found '{window.GetType().FullName}'. What it means
Prism.Maui requires the application's active window to be a PrismWindow (its own Window subclass carrying CurrentPage state). GetCurrentPage throws InvalidOperationException with the concrete offending type name when windowManager.Current is any other Window - typically a plain Microsoft.Maui.Controls.Window created by the default MAUI template.
Solutions
- Change CreateWindow to return a PrismWindow: `protected override Window CreateWindow(IActivationState state) => new PrismWindow(...);`
- Let Prism create the window automatically (remove custom CreateWindow override) and configure the app via PrismAppBuilder.
- If Shell is required, don't use Prism's IWindowManager page extensions, which assume PrismWindow.
Example fix
// before protected override Window CreateWindow(IActivationState s) => new Window(startupPage); // after protected override Window CreateWindow(IActivationState s) => new PrismWindow(startupPage);
Defensive patterns
Strategy: validation
Validate before calling
if (Application.Current?.Windows.Any(w => w is not PrismWindow) ?? false)
throw new InvalidOperationException("All windows must be PrismWindow for Prism.Maui"); Type guard
bool IsPrismHosted(IWindowManager wm) => wm.Current is PrismWindow;
Try / catch
try { var page = windowManager.GetCurrentPage(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("PrismWindow"))
{
// fix CreateWindow to return a PrismWindow
} Prevention
- Never return plain Window from CreateWindow in a Prism.Maui app
- Don't mix MAUI Shell window management with Prism WindowManager
- After Prism upgrades, re-check that window creation still uses PrismWindow
When it happens
Trigger: Overriding CreateWindow to `return new Window(page);` instead of PrismWindow; using MAUI Shell (Shell windows) with Prism's WindowManager extensions; another library swapping the application's main Window.
Common situations: New MAUI projects created from the default template then adding Prism, without removing the default `new Window(this)` in MauiProgram/App; mixing Shell and Prism navigation.
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
- The current window ' ' is not a PrismWindow.
- No Window has been set in the Application
- No current page has been set.
- Expected Navigation Failed. No Root Window has been created.
- The object must be of type
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/0c912340ee21d148.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs:40
/// <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)