{"record":{"id":"ce0cffcd174ad13f","repo":"PrismLibrary/Prism","slug":"value-cannot-be-null-parameter-view-ce0cff","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/NavigationRegistrationExtensions.cs","lineNumber":19,"sourceCode":"﻿using System.Diagnostics.CodeAnalysis;\nusing Prism.Mvvm;\n\nnamespace Prism.Ioc;\n\npublic static class NavigationRegistrationExtensions\n{\n    public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IContainerRegistry container, string name = null)\n        where TView : Page =>\n        container.RegisterForNavigation(typeof(TView), null, name);\n\n    public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry container, string name = null)\n        where TView : Page =>\n        container.RegisterForNavigation(typeof(TView), typeof(TViewModel), name);\n\n    public static IContainerRegistry RegisterForNavigation(this IContainerRegistry container, Type view, Type viewModel, string name = null)\n    {\n        if (view is null)\n            throw new ArgumentNullException(nameof(view));\n\n        if (string.IsNullOrEmpty(name))\n            name = view.Name;\n\n        container.RegisterInstance(new ViewRegistration\n            {\n                Type = ViewType.Page,\n                Name = name,\n                View = view,\n                ViewModel = viewModel\n            })\n            .Register(view);\n\n        if (viewModel != null)\n            container.Register(viewModel);\n\n        return container;\n    }","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Ioc/NavigationRegistrationExtensions.cs#L1-L37","documentation":"The IContainerRegistry.RegisterForNavigation extension throws ArgumentNullException when the view Type is null. As with the IServiceCollection overload, Prism requires a real Page-derived view type to build a ViewRegistration and register it in the container.","triggerScenarios":"Calling containerRegistry.RegisterForNavigation(null, typeof(MyViewModel)) or passing a null result from reflection-based type resolution (e.g. Type.GetType(name) returning null for an unresolvable assembly-qualified name).","commonSituations":"Custom app builders registering modules by type name from config; module assemblies not loaded so Type.GetType returns null; typos in fully-qualified type names.","solutions":["Pass a concrete Page type: containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>()","Guard reflection lookups: if type is null, throw or log before registering","Confirm the module/view assembly is referenced and loaded before registration"],"exampleFix":"// before\nvar viewType = Assembly.GetExecutingAssembly().GetType(viewName);\ncontainerRegistry.RegisterForNavigation(viewType, viewModelType);\n// after\nvar viewType = Assembly.GetExecutingAssembly().GetType(viewName) ?? throw new InvalidOperationException($\"View '{viewName}' not found\");\ncontainerRegistry.RegisterForNavigation(viewType, viewModelType);","handlingStrategy":"validation","validationCode":"var viewType = Type.GetType(viewTypeName);\nif (viewType is null)\n    throw new InvalidOperationException($\"View type '{viewTypeName}' not found — check assembly qualification\");\ncontainerRegistry.RegisterForNavigation(viewType, viewModelType);","typeGuard":"bool IsResolvablePageType(string name) => Type.GetType(name) is { } t && typeof(Page).IsAssignableFrom(t);","tryCatchPattern":"try\n{\n    containerRegistry.RegisterForNavigation(viewType, viewModelType);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"view\")\n{\n    logger.LogError(ex, \"Cannot register navigation: view type is null\");\n}","preventionTips":["Use AssemblyQualifiedName strings when resolving types by name from config","Ensure module assemblies are loaded before catalog building","Favor generic overloads over reflection-based registration"],"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"}