{"record":{"id":"6335f000649ebcf1","repo":"PrismLibrary/Prism","slug":"the-dialog-view-fullname-must-inherit-from-microsoft-maui","errorCode":null,"errorMessage":"The Dialog '{view.FullName}' must inherit from Microsoft.Maui.Controls.View","messagePattern":"The Dialog '(.+?)' must inherit from Microsoft\\.Maui\\.Controls\\.View","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Ioc/DialogRegistrationExtensions.cs","lineNumber":137,"sourceCode":"        return services;\n    }\n\n    /// <summary>\n    /// Registers a dialog container in the service collection.\n    /// </summary>\n    /// <typeparam name=\"T\">The type of the dialog container.</typeparam>\n    /// <param name=\"services\">The service collection.</param>\n    /// <returns>The service collection.</returns>\n    public static IServiceCollection RegisterDialogContainer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IServiceCollection services)\n        where T : class, IDialogContainer =>\n        services.AddTransient<IDialogContainer, T>();\n\n    private static ViewRegistration GetViewRegistration(Type view, Type viewModel, string name)\n    {\n        ArgumentNullException.ThrowIfNull(view);\n\n        if (!view.IsAssignableTo(typeof(View)))\n            throw new InvalidOperationException($\"The Dialog '{view.FullName}' must inherit from Microsoft.Maui.Controls.View\");\n\n        if (string.IsNullOrEmpty(name))\n            name = view.Name;\n\n        return new ViewRegistration\n        {\n            Type = ViewType.Dialog,\n            Name = name,\n            View = view,\n            ViewModel = viewModel\n        };\n    }\n}\n","sourceCodeStart":119,"sourceCodeEnd":151,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Ioc/DialogRegistrationExtensions.cs#L119-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the dialog view a class deriving from Microsoft.Maui.Controls.View (ContentPage or ContentView).","Check the generic argument order: RegisterDialog<TView, TViewModel>() — the first type must be the view.","Don't register a ViewModel, interface, or non-visual type as the dialog view.","If migrating from WPF Prism, recreate the dialog as a MAUI ContentPage/ContentView with prism:ViewModelLocator.AutoWireViewModel=\"True\"."],"exampleFix":"// before\ncontainer.RegisterDialog<MyDialogViewModel, MyDialogViewModel>(); // VM passed as view\n// after\ncontainer.RegisterDialog<MyDialogPage, MyDialogViewModel>(); // MyDialogPage : ContentPage","handlingStrategy":"validation","validationCode":"if (!typeof(View).IsAssignableFrom(typeof(TView)))\n    throw new InvalidOperationException($\"{typeof(TView).Name} must inherit Microsoft.Maui.Controls.View\");","typeGuard":"bool IsValidDialogView<TView>() => typeof(TView).IsAssignableTo(typeof(View));","tryCatchPattern":"try { container.RegisterDialog<TView, TViewModel>(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"must inherit\"))\n{ logger.Error(ex, \"Invalid dialog view registration\"); }","preventionTips":["Ensure dialog views derive from ContentPage or ContentView (both are View subclasses).","Check generic argument order in RegisterDialog<TView, TViewModel>.","Never pass a ViewModel or non-visual type as the view argument."],"tags":["prism","maui","dialogs","registration","dependency-injection"],"backgroundTag":"invalid-argument-value","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"}