{"record":{"id":"4020f7004bf76d02","repo":"PrismLibrary/Prism","slug":"the-resolved-type-for-segmentname-was-null-you-may-be","errorCode":null,"errorMessage":"The resolved type for {segmentName} was null. You may be attempting to navigate to a Non-Page type","messagePattern":"The resolved type for (.+?) was null\\. You may be attempting to navigate to a Non-Page type","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/PageNavigationService.cs","lineNumber":937,"sourceCode":"            {\n                MvvmHelpers.OnNavigatedFrom(navigationPage.CurrentPage, parameters);\n            }\n            else if (tabbedPage.BindingContext != tabbedPage.CurrentPage.BindingContext)\n            {\n                MvvmHelpers.OnNavigatedFrom(tabbedPage.CurrentPage, parameters);\n            }\n        }\n    }\n\n    protected virtual Page CreatePage(string segmentName)\n    {\n        try\n        {\n            var scope = _container.CreateScope();\n            var page = (Page)Registry.CreateView(scope, segmentName);\n\n            if (page is null)\n                throw new NullReferenceException($\"The resolved type for {segmentName} was null. You may be attempting to navigate to a Non-Page type\");\n\n            return page;\n        }\n        catch(NavigationException)\n        {\n            throw;\n        }\n        catch(KeyNotFoundException knfe)\n        {\n            throw new NavigationException(NavigationException.NoPageIsRegistered, segmentName, knfe);\n        }\n        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\"))","sourceCodeStart":919,"sourceCodeEnd":955,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs#L919-L955","documentation":"During CreatePage, Prism resolved a view for the segment via Registry.CreateView but the result could not be cast/returned as a Page (null). This indicates the registration mapped the name to something that is not a Xamarin/MAUI Page.","triggerScenarios":"Navigating to a segment name whose container registration resolves a non-Page (service, view model, ContentView) or whose factory returns null.","commonSituations":"Registering a ViewModel by the same name used for navigation; registering a ContentView/Control instead of a ContentPage; a custom registry/factory returning null for unconfigured names.","solutions":["Register the segment name against a Page type: containerRegistry.RegisterForNavigation<ViewB, ViewBViewModel>()","Verify the registered type derives from Page (ContentPage, TabbedPage, NavigationPage...)","If using a custom view-creation factory, ensure it never returns null and throws a descriptive exception instead"],"exampleFix":"// before\ncontainerRegistry.Register<ViewBViewModel>(); // name 'ViewB' resolves to a VM, not a Page\n// after\ncontainerRegistry.RegisterForNavigation<ViewB, ViewBViewModel>();","handlingStrategy":"type-guard","validationCode":"var known = containerRegistry.IsRegistered<Page>(segmentName); // verify before navigating","typeGuard":"static bool IsNavigablePage(object? v) => v is Page;","tryCatchPattern":"try { await _navigationService.NavigateAsync(segment); }\ncatch (NullReferenceException nre) when (nre.Message.Contains(\"Non-Page type\")) { /* fix registration */ }","preventionTips":["Always use RegisterForNavigation for navigation targets","Never register a ViewModel or ContentView under a navigation segment name","Assert registered types derive from Page in startup diagnostics"],"tags":["prism","maui","navigation","dependency-injection"],"backgroundTag":"resource-not-found","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"}