PrismLibrary/Prism · error · InvalidOperationException

The Dialog ' ' must inherit from…

Error message

The Dialog '{view.FullName}' must inherit from Microsoft.Maui.Controls.View

What it means

When registering a dialog, DialogRegistrationExtensions validates that the view type derives from Microsoft.Maui.Controls.View, because dialog views are instantiated as visual elements and cast to View by IDialogViewRegistry. Registering a non-View type (e.g. a plain class or a ContentPage/Page type instead of a View-based ContentPage in MAUI terms is fine, but a non-visual type is not) throws InvalidOperationException.

Solutions

  1. Make the dialog view a class deriving from Microsoft.Maui.Controls.View (ContentPage or ContentView).
  2. Check the generic argument order: RegisterDialog<TView, TViewModel>() — the first type must be the view.
  3. Don't register a ViewModel, interface, or non-visual type as the dialog view.
  4. If migrating from WPF Prism, recreate the dialog as a MAUI ContentPage/ContentView with prism:ViewModelLocator.AutoWireViewModel="True".

Example fix

// before
container.RegisterDialog<MyDialogViewModel, MyDialogViewModel>(); // VM passed as view
// after
container.RegisterDialog<MyDialogPage, MyDialogViewModel>(); // MyDialogPage : ContentPage
Defensive patterns

Strategy: validation

Validate before calling

if (!typeof(View).IsAssignableFrom(typeof(TView)))
    throw new InvalidOperationException($"{typeof(TView).Name} must inherit Microsoft.Maui.Controls.View");

Type guard

bool IsValidDialogView<TView>() => typeof(TView).IsAssignableTo(typeof(View));

Try / catch

try { container.RegisterDialog<TView, TViewModel>(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("must inherit"))
{ logger.Error(ex, "Invalid dialog view registration"); }

Prevention

When it happens

Trigger: Calling container.RegisterDialog<TView, TViewModel>() (or the named overload, via GetViewRegistration) where TView does not inherit from Microsoft.Maui.Controls.View — e.g. a UserControl-like custom class, a ContentView is fine but a plain object/ViewModel or a type from a different UI framework is not.

Common situations: Registering a ViewModel or interface as the view by mistake; passing the wrong generic argument order (view vs viewModel swapped); copying WPF Prism dialog registrations where views derive from UserControl, into MAUI where the base must be View.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Ioc/DialogRegistrationExtensions.cs:137

        return services;
    }

    /// <summary>
    /// Registers a dialog container in the service collection.
    /// </summary>
    /// <typeparam name="T">The type of the dialog container.</typeparam>
    /// <param name="services">The service collection.</param>
    /// <returns>The service collection.</returns>
    public static IServiceCollection RegisterDialogContainer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IServiceCollection services)
        where T : class, IDialogContainer =>
        services.AddTransient<IDialogContainer, T>();

    private static ViewRegistration GetViewRegistration(Type view, Type viewModel, string name)
    {
        ArgumentNullException.ThrowIfNull(view);

        if (!view.IsAssignableTo(typeof(View)))
            throw new InvalidOperationException($"The Dialog '{view.FullName}' must inherit from Microsoft.Maui.Controls.View");

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

        return new ViewRegistration
        {
            Type = ViewType.Dialog,
            Name = name,
            View = view,
            ViewModel = viewModel
        };
    }
}

View on GitHub (pinned to 358118cd64)