{"record":{"id":"774aaeefbbc51e80","repo":"lepoco/wpfui","slug":"typeof-tpage-page-not-found","errorCode":null,"errorMessage":"{typeof(TPage)} page not found.","messagePattern":"(.+?) page not found\\.","errorType":"exception","errorClass":"NavigationException","httpStatus":null,"severity":"error","filePath":"src/Wpf.Ui.Abstractions/NavigationViewPageProviderExtensions.cs","lineNumber":37,"sourceCode":"    public static TPage? GetPage<TPage>(this INavigationViewPageProvider navigationViewPageProvider)\n        where TPage : class\n    {\n        return navigationViewPageProvider.GetPage(typeof(TPage)) as TPage;\n    }\n\n    /// <summary>\n    /// Retrieves a page of the specified type from the page service.\n    /// Throws a NavigationException if the page is not found.\n    /// </summary>\n    /// <typeparam name=\"TPage\">The type of the page to retrieve.</typeparam>\n    /// <param name=\"navigationViewPageProvider\">The page service instance.</param>\n    /// <returns>An instance of the specified page type.</returns>\n    /// <exception cref=\"NavigationException\">Thrown when the specified page type is not found.</exception>\n    public static TPage GetRequiredPage<TPage>(this INavigationViewPageProvider navigationViewPageProvider)\n        where TPage : class\n    {\n        return navigationViewPageProvider.GetPage(typeof(TPage)) as TPage\n            ?? throw new NavigationException($\"{typeof(TPage)} page not found.\");\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":40,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui.Abstractions/NavigationViewPageProviderExtensions.cs#L19-L40","documentation":"GetRequiredPage<TPage> is an extension method on INavigationViewPageProvider that calls GetPage(typeof(TPage)) and throws NavigationException if it returns null. It is the strict variant of GetPage for cases where the caller cannot proceed without the page. A null result means the provider has no mapping/registration for the requested page type.","triggerScenarios":"Calling GetRequiredPage<TPage>() for a TPage that the page provider does not know how to build - because it was never registered, the DI container cannot resolve it, or the provider's dictionary lacks the mapping.","commonSituations":"Forgetting to register a page in a custom INavigationViewPageProvider; the page type requested differs from the registered type (e.g. interface vs concrete); the underlying service returns null due to a missing DI registration.","solutions":["Register the page type with your INavigationViewPageProvider / DI container so GetPage returns a non-null instance.","Ensure you request the exact type the provider resolves (concrete class, not an interface or base).","Use the non-throwing GetPage when absence is expected, and only call GetRequiredPage when the page is mandatory."],"exampleFix":"// before\npublic class PageService : INavigationViewPageProvider\n{\n    public object? GetPage(Type t) => null; // nothing registered\n}\nvar page = provider.GetRequiredPage<DashboardPage>(); // throws\n\n// after\npublic class PageService(IServiceProvider sp) : INavigationViewPageProvider\n{\n    public object? GetPage(Type t) => sp.GetService(t);\n}\n// plus: services.AddTransient<DashboardPage>();","handlingStrategy":"try-catch","validationCode":"var page = provider.GetPage(typeof(TPage));\nif (page is null)\n{\n    throw new NavigationException($\"{typeof(TPage)} not registered in the page provider.\");\n}","typeGuard":"static bool IsPageRegistered(INavigationViewPageProvider p, Type t) => p.GetPage(t) is not null;","tryCatchPattern":"try { var page = provider.GetRequiredPage<TPage>(); }\ncatch (NavigationException ex)\n{\n    _logger.LogError(ex, \"Page {Page} not found; ensure it is registered.\", typeof(TPage));\n    return;\n}","preventionTips":["Register every page type in your INavigationViewPageProvider/DI container.","Request the concrete page type that was registered.","Use GetPage when absence is acceptable; reserve GetRequiredPage for mandatory pages."],"tags":["navigation","page-provider","navigation-exception","wpf"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}