{"record":{"id":"f69306107cad7803","repo":"PrismLibrary/Prism","slug":"no-window-has-been-set-in-the-application","errorCode":null,"errorMessage":"No Window has been set in the Application","messagePattern":"No Window has been set in the Application","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs","lineNumber":38,"sourceCode":"    }\n\n    /// <summary>\n    /// Gets the <see cref=\"IDialogService\"/> for the currently displayed <see cref=\"Page\"/>.\n    /// </summary>\n    /// <param name=\"windowManager\">The <see cref=\"IWindowManager\"/>.</param>\n    /// <returns>The <see cref=\"IDialogService\"/> for the current <see cref=\"Page\"/>.</returns>\n    public static IDialogService GetCurrentDialogService(this IWindowManager windowManager)\n    {\n        var page = windowManager.GetCurrentPage();\n        var container = page.GetContainerProvider();\n        return container.Resolve<IDialogService>();\n    }\n\n    private static Page GetCurrentPage(this IWindowManager windowManager)\n    {\n        var window = windowManager.Current;\n        if (window is null)\n            throw new InvalidOperationException(\"No Window has been set in the Application\");\n        else if (window is not PrismWindow prismWindow)\n            throw new InvalidOperationException($\"Prism applications only support the use of PrismWindow, but found '{window.GetType().FullName}'.\");\n        else if (prismWindow.CurrentPage is null)\n            throw new InvalidOperationException(\"No current page has been set.\");\n        else\n            return prismWindow.CurrentPage;\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":47,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs#L20-L47","documentation":"The internal GetCurrentPage extension on IWindowManager reads windowManager.Current; if no window has been activated/registered with Prism yet, it throws InvalidOperationException('No Window has been set in the Application'). It exists so page-related helper extensions can fail loudly instead of returning a null Page.","triggerScenarios":"Calling an IWindowManager extension that relies on GetCurrentPage (e.g. GetNavigationService/GetPageScope helpers) before CreateWindow has run, or after the application's windows were cleared/closed.","commonSituations":"Accessing page/window services in App constructor or OnStartup before window creation; calling extensions from a background thread very early in launch; MAUI apps that override window creation and never register the window with Prism's WindowManager.","solutions":["Defer the call until after a Prism window exists (e.g. inside OnCreated/OnNavigatedTo of the first page, not App startup).","Ensure App.CreateWindow is overridden per Prism docs (returning a PrismWindow) so the WindowManager gets a Current window.","If you only need the service, resolve IWindowManager only after window creation, or guard with `windowManager.Current is null` checks."],"exampleFix":"// before\npublic App() { var page = windowManager.GetCurrentPage(); } // no window yet\n// after\nprotected override Window CreateWindow(IActivationState s)\n    => new PrismWindow(new NavigationPage(...));\n// then in page lifecycle:\nOnNavigatedTo(...) => windowManager.GetCurrentPage(); // safe","handlingStrategy":"validation","validationCode":"if (windowManager.Current is null)\n    throw new InvalidOperationException(\"Call after Prism has created the application window\");","typeGuard":"bool HasActiveWindow(IWindowManager wm) => wm.Current is not null;","tryCatchPattern":"try { var page = windowManager.GetCurrentPage(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No Window has been set\"))\n{\n    // defer work until after window creation\n}","preventionTips":["Only use IWindowManager page extensions after CreateWindow completes","Do not resolve page-scoped services in the App constructor","Keep Prism's window creation flow intact (don't bypass CreateWindow)"],"tags":["prism","maui","window","lifecycle","invalid-operation"],"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"}