{"record":{"id":"87edf8cd01d16fbf","repo":"lepoco/wpfui","slug":"nameof-pageservice-nameof-pageservice-getpag","errorCode":null,"errorMessage":"{nameof(_pageService)}.{nameof(_pageService.GetPage)} returned null for type {viewItem.TargetPageType}.","messagePattern":"(.+?)\\.(.+?) returned null for type (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs","lineNumber":286,"sourceCode":"        if (viewItem.TargetPageType is null)\n        {\n            throw new InvalidOperationException(\n                $\"The {nameof(viewItem)}.{nameof(viewItem.TargetPageType)} property cannot be null.\"\n            );\n        }\n\n        if (_serviceProvider is not null)\n        {\n            return _serviceProvider.GetService(viewItem.TargetPageType)\n                ?? throw new InvalidOperationException(\n                    $\"{nameof(_serviceProvider)}.{nameof(_serviceProvider.GetService)} returned null for type {viewItem.TargetPageType}.\"\n                );\n        }\n\n        if (_pageService is not null)\n        {\n            return _pageService.GetPage(viewItem.TargetPageType)\n                ?? throw new InvalidOperationException(\n                    $\"{nameof(_pageService)}.{nameof(_pageService.GetPage)} returned null for type {viewItem.TargetPageType}.\"\n                );\n        }\n\n        return _cache.Remember(\n                viewItem.TargetPageType,\n                viewItem.NavigationCacheMode,\n                ComputeCachedNavigationInstance\n            )\n            ?? throw new InvalidOperationException(\n                $\"Unable to get or create instance of {viewItem.TargetPageType} from cache.\"\n            );\n\n        object? ComputeCachedNavigationInstance() => GetPageInstanceFromCache(viewItem.TargetPageType);\n    }\n\n    private object? GetPageInstanceFromCache(Type? targetPageType)\n    {","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui/Controls/NavigationView/NavigationView.Navigation.cs#L268-L304","documentation":"Thrown by NavigationView.GetNavigationItemInstance when no IServiceProvider is configured but an INavigationViewPageProvider (the _pageService) is, and its GetPage(TargetPageType) returns null. The page provider is the second resolution strategy; a null means the provider does not know how to build the requested page.","triggerScenarios":"Navigating to a NavigationViewItem whose TargetPageType is not handled by the custom INavigationViewPageProvider.GetPage implementation; the provider's dictionary/switch is missing the page; the provider returned null due to an internal error.","commonSituations":"A custom page provider that maintains an explicit map and the page was not added; provider that throws-and-swallows internally returning null; page registered under a key/type mismatch.","solutions":["Implement GetPage in your INavigationViewPageProvider to return a non-null instance for every navigable TargetPageType.","If the provider uses a dictionary, ensure all target page types are keys.","Log inside GetPage to diagnose why null is returned.","Alternatively, register the page with an IServiceProvider instead and let NavigationView resolve it."],"exampleFix":"// before\npublic object? GetPage(Type pageType) => null; // throws\n\n// after\npublic object? GetPage(Type pageType) =>\n    pageType == typeof(SettingsPage) ? new SettingsPage() : null;","handlingStrategy":"validation","validationCode":"if (_pageService.GetPage(viewItem.TargetPageType) is null)\n    throw new InvalidOperationException(\n        $\"Page provider returned null for {viewItem.TargetPageType}.\");","typeGuard":"static bool IsPageKnown(INavigationViewPageProvider p, Type t) => p.GetPage(t) is not null;","tryCatchPattern":null,"preventionTips":["Implement GetPage to cover every navigable page type.","Keep the provider's page map in sync with declared items.","Log inside GetPage to catch null-returning branches."],"tags":["wpf","navigationview","page-provider","configuration"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}