PrismLibrary/Prism · error · ArgumentNullException
Value cannot be null. (Parameter 'view')
Error message
Value cannot be null. (Parameter 'view')
What it means
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.
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
Example fix
// before
var viewType = Assembly.GetExecutingAssembly().GetType(viewName);
containerRegistry.RegisterForNavigation(viewType, viewModelType);
// after
var viewType = Assembly.GetExecutingAssembly().GetType(viewName) ?? throw new InvalidOperationException($"View '{viewName}' not found");
containerRegistry.RegisterForNavigation(viewType, viewModelType); Defensive patterns
Strategy: validation
Validate before calling
var viewType = Type.GetType(viewTypeName);
if (viewType is null)
throw new InvalidOperationException($"View type '{viewTypeName}' not found — check assembly qualification");
containerRegistry.RegisterForNavigation(viewType, viewModelType); Type guard
bool IsResolvablePageType(string name) => Type.GetType(name) is { } t && typeof(Page).IsAssignableFrom(t); Try / catch
try
{
containerRegistry.RegisterForNavigation(viewType, viewModelType);
}
catch (ArgumentNullException ex) when (ex.ParamName == "view")
{
logger.LogError(ex, "Cannot register navigation: view type is null");
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Value cannot be null. (Parameter 'view')
- The view type ' ' is not a type of Page.
- configureSegment
- Cannot destroy .
- The page type ' ' is not supported.
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/ce0cffcd174ad13f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Maui/Prism.Maui/Ioc/NavigationRegistrationExtensions.cs:19
using System.Diagnostics.CodeAnalysis;
using Prism.Mvvm;
namespace Prism.Ioc;
public static class NavigationRegistrationExtensions
{
public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IContainerRegistry container, string name = null)
where TView : Page =>
container.RegisterForNavigation(typeof(TView), null, name);
public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry container, string name = null)
where TView : Page =>
container.RegisterForNavigation(typeof(TView), typeof(TViewModel), name);
public static IContainerRegistry RegisterForNavigation(this IContainerRegistry container, Type view, Type viewModel, string name = null)
{
if (view is null)
throw new ArgumentNullException(nameof(view));
if (string.IsNullOrEmpty(name))
name = view.Name;
container.RegisterInstance(new ViewRegistration
{
Type = ViewType.Page,
Name = name,
View = view,
ViewModel = viewModel
})
.Register(view);
if (viewModel != null)
container.Register(viewModel);
return container;
}View on GitHub (pinned to 358118cd64)