PrismLibrary/Prism · error · ArgumentNullException

Value cannot be null. (Parameter 'view')

Error message

Value cannot be null. (Parameter 'view')

What it means

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.

Solutions

  1. Pass the concrete view type: services.RegisterForNavigation<MainPage, MainPageViewModel>()
  2. If resolving the Type dynamically, check it for null before calling RegisterForNavigation
  3. Verify the assembly containing the view is loaded so Type.GetType/assembly.GetType returns a real Type

Example fix

// before
var viewType = Type.GetType("MyApp.Views.MainPage");
services.RegisterForNavigation(viewType, typeof(MainPageViewModel));
// after
var viewType = Type.GetType("MyApp.Views.MainPage") ?? typeof(MyApp.Views.MainPage);
services.RegisterForNavigation(viewType, typeof(MainPageViewModel));
Defensive patterns

Strategy: validation

Validate before calling

if (viewType is null) throw new InvalidOperationException($"View type '{viewTypeName}' could not be resolved");
services.RegisterForNavigation(viewType, viewModelType);

Type guard

bool IsValidView(Type t) => t is not null && typeof(Page).IsAssignableFrom(t);

Try / catch

try
{
    services.RegisterForNavigation(viewType, viewModelType);
}
catch (ArgumentNullException ex) when (ex.ParamName == "view")
{
    logger.LogError(ex, "Navigation registration skipped: null view type");
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/985f63888f19c2f1. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/Ioc/MicrosoftDependencyInjectionExtensions.cs:25

/// Navigation Extensions for working with the <see cref="IServiceCollection"/>
/// </summary>
public static class MicrosoftDependencyInjectionExtensions
{
#if !UNO_WINUI
    private static readonly Type PageType = typeof(Page);

    public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IServiceCollection services, string name = null)
            where TView : Page =>
            services.RegisterForNavigation(typeof(TView), null, name);

    public static IServiceCollection RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IServiceCollection services, string name = null)
        where TView : Page =>
        services.RegisterForNavigation(typeof(TView), typeof(TViewModel), name);

    public static IServiceCollection RegisterForNavigation(this IServiceCollection services, Type view, Type viewModel, string name = null)
    {
        if (view is null)
            throw new ArgumentNullException(nameof(view));

        if (!view.IsAssignableTo(PageType))
            throw new InvalidOperationException($"The view type '{view.FullName}' is not a type of Page.");

        if (string.IsNullOrEmpty(name))
            name = view.Name;

        services.AddSingleton(new ViewRegistration
            {
                Type = ViewType.Page,
                Name = name,
                View = view,
                ViewModel = viewModel
            })
            .AddTransient(view);

        if (viewModel != null)
            services.AddTransient(viewModel);

View on GitHub (pinned to 358118cd64)