{"record":{"id":"985f63888f19c2f1","repo":"PrismLibrary/Prism","slug":"value-cannot-be-null-parameter-view","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'view')","messagePattern":"Value cannot be null\\. \\(Parameter 'view'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs","lineNumber":25,"sourceCode":"/// Navigation Extensions for working with the <see cref=\"IServiceCollection\"/>\n/// </summary>\npublic static class MicrosoftDependencyInjectionExtensions\n{\n#if !UNO_WINUI\n    private static readonly Type PageType = typeof(Page);\n\n    public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IServiceCollection services, string name = null)\n            where TView : Page =>\n            services.RegisterForNavigation(typeof(TView), null, name);\n\n    public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IServiceCollection services, string name = null)\n        where TView : Page =>\n        services.RegisterForNavigation(typeof(TView), typeof(TViewModel), name);\n\n    public static IServiceCollection RegisterForNavigation(this IServiceCollection services, Type view, Type viewModel, string name = null)\n    {\n        if (view is null)\n            throw new ArgumentNullException(nameof(view));\n\n        if (!view.IsAssignableTo(PageType))\n            throw new InvalidOperationException($\"The view type '{view.FullName}' is not a type of Page.\");\n\n        if (string.IsNullOrEmpty(name))\n            name = view.Name;\n\n        services.AddSingleton(new ViewRegistration\n            {\n                Type = ViewType.Page,\n                Name = name,\n                View = view,\n                ViewModel = viewModel\n            })\n            .AddTransient(view);\n\n        if (viewModel != null)\n            services.AddTransient(viewModel);","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs#L7-L43","documentation":"Prism.Maui's RegisterForNavigation extension throws ArgumentNullException when the view Type passed to it is null. Navigation registration in Prism requires a concrete Page-derived view type so it can register the view and its view model with the DI container. Passing null is always a programming mistake, so the library fails fast.","triggerScenarios":"Calling services.RegisterForNavigation(null, typeof(MyViewModel)) or RegisterForNavigation<TView>(...) where a typeof(...) expression resolves through a null reflection result (e.g. Type.GetType returned null and was passed along).","commonSituations":"Resolving view types via reflection or configuration where Type.GetType fails silently and the null Type is forwarded; refactoring that removed a Page class but left a registration referencing it dynamically.","solutions":["Pass the concrete view type: services.RegisterForNavigation<MainPage, MainPageViewModel>()","If resolving the Type dynamically, check it for null before calling RegisterForNavigation","Verify the assembly containing the view is loaded so Type.GetType/assembly.GetType returns a real Type"],"exampleFix":"// before\nvar viewType = Type.GetType(\"MyApp.Views.MainPage\");\nservices.RegisterForNavigation(viewType, typeof(MainPageViewModel));\n// after\nvar viewType = Type.GetType(\"MyApp.Views.MainPage\") ?? typeof(MyApp.Views.MainPage);\nservices.RegisterForNavigation(viewType, typeof(MainPageViewModel));","handlingStrategy":"validation","validationCode":"if (viewType is null) throw new InvalidOperationException($\"View type '{viewTypeName}' could not be resolved\");\nservices.RegisterForNavigation(viewType, viewModelType);","typeGuard":"bool IsValidView(Type t) => t is not null && typeof(Page).IsAssignableFrom(t);","tryCatchPattern":"try\n{\n    services.RegisterForNavigation(viewType, viewModelType);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"view\")\n{\n    logger.LogError(ex, \"Navigation registration skipped: null view type\");\n}","preventionTips":["Prefer the generic RegisterForNavigation<TView, TViewModel>() overload so the type is checked at compile time","Never pass reflection results directly to registration APIs without a null check","Register views explicitly with typeof(...) rather than from config strings"],"tags":["null-argument","di-registration","navigation","maui"],"backgroundTag":"null-argument","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"}