PrismLibrary/Prism · error · InvalidOperationException
There is no Prism Window currently displayed.
Error message
There is no Prism Window currently displayed.
What it means
PageDialogService.GetPage resolves the current window via IWindowManager and requires it to be a PrismWindow; otherwise it throws this InvalidOperationException. Dialog APIs (alerts, action sheets, prompts) need a live Prism window and current page to display on.
Solutions
- Only invoke dialog APIs after the Prism window is shown — e.g. defer dialog calls until after initial navigation completes (OnNavigatedTo or an event after window activation).
- Ensure the app window is a PrismWindow (created through Prism's CreateWindow pipeline, not a raw Microsoft.Maui.Controls.Window).
- Check IWindowManager.Current for null/non-PrismWindow before calling dialog methods.
- In tests or services, abstract the dialog service behind an interface and inject a fake instead of hitting the real window.
Example fix
// before: dialog during constructor, before window exists
public MainViewModel(IPageDialogService dialogs) => dialogs.DisplayAlertAsync("Hi", "Welcome", "OK");
// after: show after navigation
public void OnNavigatedTo(INavigationParameters parameters) =>
_dialogs.DisplayAlertAsync("Hi", "Welcome", "OK"); Defensive patterns
Strategy: validation
Validate before calling
bool canShowDialog = _windowManager.Current is PrismWindow w && w.CurrentPage is not null;
Type guard
static bool HasActivePrismWindow(IWindowManager wm) => wm.Current is PrismWindow;
Try / catch
if (_windowManager.Current is not PrismWindow)
return; // or queue the dialog
await _dialogs.DisplayAlertAsync(title, message, "OK"); Prevention
- Show dialogs only after navigation/window activation (e.g. OnNavigatedTo), never in constructors.
- Do not replace PrismWindow with a custom Window type when using PageDialogService.
- Queue or drop dialogs requested while no window is displayed.
- Use a fake IPageDialogService in tests and headless services.
When it happens
Trigger: Calling DisplayAlertAsync/DisplayActionSheetAsync/DisplayPromptAsync when no PrismWindow is currently displayed — e.g. before the app window is created, after the window was closed, when using a custom window not derived from PrismWindow, or from a background context (ViewModel constructed pre-window, service, or unit test).
Common situations: Showing dialogs during startup before CreateWindow completes; attempting dialogs after the last window closed on desktop platforms; replacing PrismWindow with a custom Window type; calling dialog service from a headless service/test.
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
- The current window ' ' is not a PrismWindow.
- At least one button needs to be supplied
- Unable to determine the current page.
- Error creating dialog
- CanClose returned false
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/eba7691cfcec4d87.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Services/PageDialogs/PageDialogService.cs:186
/// <param name="title">Title to display</param>
/// <param name="message">Message to display</param>
/// <param name="accept">Text for the accept button</param>
/// <param name="cancel">Text for the cancel button</param>
/// <param name="placeholder">Placeholder text to display in the prompt</param>
/// <param name="maxLength">Maximum length of the user response</param>
/// <param name="keyboardType">Keyboard type to use for the user response</param>
/// <param name="initialValue">Pre-defined response that will be displayed, and which can be edited</param>
/// <returns><c>string</c> entered by the user. <c>null</c> if cancel is pressed</returns>
public virtual Task<string> DisplayPromptAsync(string title, string message, string accept = "OK", string cancel = "Cancel", string placeholder = default, int maxLength = -1, KeyboardType keyboardType = KeyboardType.Default, string initialValue = "")
{
var keyboard = _keyboardMapper.Map(keyboardType);
return GetPage().DisplayPromptAsync(title, message, accept, cancel, placeholder, maxLength, keyboard, initialValue);
}
private Page GetPage()
{
if (_windowManager.Current is not PrismWindow window)
throw new InvalidOperationException("There is no Prism Window currently displayed.");
return window.CurrentPage;
}
}
View on GitHub (pinned to 358118cd64)