{"record":{"id":"29348e602f5619d1","repo":"PrismLibrary/Prism","slug":"no-current-page-has-been-set","errorCode":null,"errorMessage":"No current page has been set.","messagePattern":"No current page has been set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs","lineNumber":42,"sourceCode":"    /// </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":24,"sourceCodeEnd":47,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/IWindowManagerExtensions.cs#L24-L47","documentation":"GetCurrentPage found a valid PrismWindow but its CurrentPage is null - the window exists but Prism has not set/assigned the active page yet (or it was cleared). It throws InvalidOperationException('No current page has been set.') rather than returning null.","triggerScenarios":"Calling page-dependent IWindowManager extensions during window construction before the first page finishes navigation; after a window's content is replaced manually without going through Prism navigation; on a freshly created PrismWindow with no content.","commonSituations":"Calling GetPageScope/GetNavigationService-style extensions inside CreateWindow or a page constructor too early; performing window work on app resume before navigation completes; forcing `new PrismWindow()` without a page and navigating later.","solutions":["Move the call to after navigation completes (OnNavigatedTo / NavigationCompleted), not the page constructor.","Create the PrismWindow with an initial page: `new PrismWindow(new NavigationPage().WithNavigationService(...))` per Prism startup docs.","Guard the call: check `prismWindow.CurrentPage` (or CurrentWindow state) before invoking extensions that depend on the current page."],"exampleFix":"// before\npublic MyPage() { var page = windowManager.GetCurrentPage(); } // CurrentPage not yet set\n// after\npublic void OnNavigatedTo(INavigationParameters p)\n{\n    var page = windowManager.GetCurrentPage(); // safe now\n}","handlingStrategy":"validation","validationCode":"if (windowManager.Current is PrismWindow pw && pw.CurrentPage is null)\n    throw new InvalidOperationException(\"CurrentPage not yet set; call after navigation completes\");","typeGuard":"bool HasCurrentPage(IWindowManager wm) => wm.Current is PrismWindow { CurrentPage: not null };","tryCatchPattern":"try { var page = windowManager.GetCurrentPage(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No current page has been set\"))\n{\n    // retry after OnNavigatedTo / navigation completion\n}","preventionTips":["Access the current page only in OnNavigatedTo or later lifecycle events","Always create PrismWindow with an initial page","Avoid replacing window content outside Prism's navigation APIs"],"tags":["prism","maui","window","lifecycle","currentpage"],"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"}