{"record":{"id":"b01e858220b90cba","repo":"PrismLibrary/Prism","slug":"there-is-currently-no-application-window","errorCode":null,"errorMessage":"There is currently no application window.","messagePattern":"There is currently no application window\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Dialogs/SingletonDialogService.cs","lineNumber":33,"sourceCode":"public sealed class SingletonDialogService : DialogServiceBase\n{\n    private readonly IWindowManager _windowManager;\n\n    /// <summary>\n    /// Initializes a new SingletonDialogService\n    /// </summary>\n    /// <param name=\"windowManager\">An instance of the <see cref=\"IWindowManager\"/>.</param>\n    public SingletonDialogService(IWindowManager windowManager)\n    {\n        ArgumentNullException.ThrowIfNull(windowManager);\n        _windowManager = windowManager;\n    }\n\n    /// <inheritdoc/>\n    protected override Page? GetCurrentPage()\n    {\n        if (_windowManager.Current is null)\n            throw new NotSupportedException(\"There is currently no application window.\");\n        else if (_windowManager.Current is not PrismWindow prismWindow)\n            throw new NotSupportedException($\"The current window '{_windowManager.Current.GetType().FullName}' is not a PrismWindow.\");\n        else\n            return prismWindow.CurrentPage;\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":40,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Dialogs/SingletonDialogService.cs#L15-L40","documentation":"SingletonDialogService.GetCurrentPage needs the app's current window to find the page hosting a dialog. If IWindowManager.Current is null — no window exists yet or all windows were closed — it throws NotSupportedException \"There is currently no application window.\". Dialogs cannot be shown or closed without an active window.","triggerScenarios":"Calling ShowDialog/CloseDialogAsync before the MAUI window is created (e.g. in OnStart before window assignment, in a constructor run at app init) or after the last window was closed; a background service attempting to open a dialog with no UI window.","commonSituations":"Showing a dialog from App constructor / startup code; unit-test or design-time environments without a window; calling dialogs from a headless/background path (push-notification handler) when the app was relaunched without UI.","solutions":["Defer dialog calls until a window exists (e.g. wait for the first Page's OnAppearing or the Window created event).","Check IWindowManager.Current (or Application.Windows) for null before requesting dialogs.","Route background-triggered dialogs through a queue that shows them once the window is ready.","Catch NotSupportedException and fall back to a non-UI notification."],"exampleFix":"// before\nOnInitialized(); // ShowDialog called immediately\n// after\nprotected override void OnWindowCreated(Window window)\n{\n    base.OnWindowCreated(window);\n    ShowPendingDialog(); // window now exists\n}","handlingStrategy":"type-guard","validationCode":"if (Application.Current?.Windows?.Any() != true)\n    return; // no window yet — defer the dialog","typeGuard":"bool HasWindow(IWindowManager wm) => wm.Current is not null;","tryCatchPattern":"try { await dialogService.ShowDialogAsync(name); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"no application window\"))\n{ QueueDialogUntilWindowReady(name); }","preventionTips":["Never show dialogs from App constructor or before the window is created.","Queue UI requests from background services until the window exists.","Gate dialog calls behind a 'window ready' event or lifecycle check."],"tags":["prism","maui","dialogs","window-lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}