{"record":{"id":"bed90ac606ee2026","repo":"PrismLibrary/Prism","slug":"navigationexception-errorcreatingpage","errorCode":"NavigationException.ErrorCreatingPage","errorMessage":"NavigationException.ErrorCreatingPage","messagePattern":"NavigationException\\.ErrorCreatingPage","errorType":"exception","errorClass":"NavigationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/PageNavigationService.cs","lineNumber":967,"sourceCode":"        catch(ViewModelCreationException vmce)\n        {\n            throw new NavigationException(NavigationException.ErrorCreatingViewModel, segmentName, _pageAccessor.Page, vmce);\n        }\n        //catch(ViewCreationException viewCreationException)\n        //{\n        //    if(!string.IsNullOrEmpty(viewCreationException.InnerException?.Message) && viewCreationException.InnerException.Message.Contains(\"Maui\"))\n        //        throw new NavigationException(NavigationException.)\n        //}\n        catch (Exception ex)\n        {\n            var inner = ex.InnerException;\n            while(inner is not null)\n            {\n                if (inner.Message.Contains(\"thread with a dispatcher\"))\n                    throw new NavigationException(NavigationException.UnsupportedMauiCreation, segmentName, _pageAccessor.Page, ex);\n                inner = inner.InnerException;\n            }\n            throw new NavigationException(NavigationException.ErrorCreatingPage, segmentName, ex);\n        }\n    }\n\n    protected virtual Page CreatePageFromSegment(string segment)\n    {\n        string segmentName = UriParsingHelper.GetSegmentName(segment);\n        var page = CreatePage(segmentName);\n        if (page is null)\n        {\n            var innerException = new NullReferenceException(string.Format(\"{0} could not be created. Please make sure you have registered {0} for navigation.\", segmentName));\n            throw new NavigationException(NavigationException.NoPageIsRegistered, segmentName, _pageAccessor.Page, innerException);\n        }\n\n        return page;\n    }\n\n    async Task ConfigureTabbedPage(TabbedPage tabbedPage, string segment, INavigationParameters parameters)\n    {","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs#L949-L985","documentation":"This is the generic fallback in CreatePage: an exception occurred while instantiating the Page for a segment and it was not a NavigationException, KeyNotFoundException, ViewModelCreationException, or the dispatcher-thread case. Prism wraps it as NavigationException.ErrorCreatingPage with the segment name and original exception as InnerException.","triggerScenarios":"A Page's constructor or XAML load throws (missing resource/image, StaticResource key not found, x:Static failure, ctor exception); any non-registered exception type bubbling out of Registry.CreateView.","commonSituations":"XAML referencing a missing namespace, converter, or style; a page constructor throwing (file I/O, null config); version upgrades where a control no longer exists.","solutions":["Inspect the InnerException (the original ex) for the real cause and fix that","Check the page's constructor and XAML for throwing code and missing resources/converters","Register any services used in the page constructor so construction completes"],"exampleFix":"// before\npublic ViewBPage() { InitializeComponent(); LoadConfig(); // throws off main path\n// after\npublic ViewBPage() { InitializeComponent(); }\nprotected override void OnNavigatedTo(INavigationParameters p) { SafeLoadConfig(); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await _navigationService.NavigateAsync(segment); }\ncatch (NavigationException ne) when (ne.Message == NavigationException.ErrorCreatingPage)\n{ Log(ne.InnerException); ShowFallbackPage(); }","preventionTips":["Keep page constructors trivial; defer work to OnNavigatedTo/OnAppearing","Validate XAML resources (converters, styles, images) at build/preview time","Test navigation to every page once in a smoke test"],"tags":["prism","maui","navigation","xaml"],"backgroundTag":"internal-invariant-violation","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"}