{"record":{"id":"635e959ee9248fcc","repo":"PrismLibrary/Prism","slug":"a-dialog-s-content-must-be-an-avalonia-controls-control","errorCode":null,"errorMessage":"A dialog's content must be an Avalonia.Controls.Control","messagePattern":"A dialog's content must be an Avalonia\\.Controls\\.Control","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"src/Avalonia/Prism.Avalonia/Dialogs/DialogService.cs","lineNumber":89,"sourceCode":"        protected virtual IDialogWindow CreateDialogWindow(string name)\n        {\n            if (string.IsNullOrWhiteSpace(name))\n                return _containerExtension.Resolve<IDialogWindow>();\n            else\n                return _containerExtension.Resolve<IDialogWindow>(name);\n        }\n\n        /// <summary>\n        /// Configure <see cref=\"IDialogWindow\"/> content.\n        /// </summary>\n        /// <param name=\"dialogName\">The name of the dialog to show.</param>\n        /// <param name=\"window\">The hosting window.</param>\n        /// <param name=\"parameters\">The parameters to pass to the dialog.</param>\n        protected virtual void ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters)\n        {\n            var content = _containerExtension.Resolve<object>(dialogName);\n            if (!(content is Avalonia.Controls.Control dialogContent))\n                throw new NullReferenceException(\"A dialog's content must be an Avalonia.Controls.Control\");\n\n            MvvmHelpers.AutowireViewModel(dialogContent);\n\n            if (!(dialogContent.DataContext is IDialogAware viewModel))\n                throw new NullReferenceException(\"A dialog's ViewModel must implement the IDialogAware interface\");\n\n            ConfigureDialogWindowProperties(window, dialogContent, viewModel);\n\n            MvvmHelpers.ViewAndViewModelAction<IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));\n        }\n\n        /// <summary>\n        /// Configure <see cref=\"IDialogWindow\"/> and <see cref=\"IDialogAware\"/> events.\n        /// </summary>\n        /// <param name=\"dialogWindow\">The hosting window.</param>\n        /// <param name=\"callback\">The action to perform when the dialog is closed.</param>\n        protected virtual void ConfigureDialogWindowEvents(IDialogWindow dialogWindow, DialogCallback callback)\n        {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Avalonia/Prism.Avalonia/Dialogs/DialogService.cs#L71-L107","documentation":"Prism's DialogService resolves the view for a registered dialog name from the container and requires the resolved object to be an Avalonia.Controls.Control so it can be placed in the dialog window's content. If the container resolves something else (or the type registered under that name is not a Control), a NullReferenceException with this message is thrown from ConfigureDialogWindowContent.","triggerScenarios":"Calling dialogService.ShowDialog(\"MyDialog\") where the type registered under name \"MyDialog\" does not derive from Avalonia.Controls.Control, or containerExtensions.RegisterDialog registers a non-Control view (e.g. only a ViewModel, or a wrong base class), or the container resolves null/incorrect binding for the registered name.","commonSituations":"Registering a dialog whose 'view' is actually a UserControl from the wrong UI framework or a plain class; forgetting to update a XAML build action so the view type isn't the Control; copy-pasting a WPF/WinForms dialog registration into an Avalonia app; renaming the view but keeping the old registration.","solutions":["Ensure the type registered via containerRegistry.RegisterDialog<TView, TViewModel>() (or RegisterDialog(typeof(...), name)) is an Avalonia.Controls.Control (UserControl/Window).","Verify the registration name passed to ShowDialog matches the registered dialog name exactly.","Check that the container registration is not being overridden or resolving a different type (e.g. wrong assembly loaded, stale registration).","Confirm the view's XAML has Build Action = AvaloniaXaml / Page and the root element is a Control."],"exampleFix":"// before\ncontainerRegistry.RegisterDialog<MyDialogViewModel, MyDialogViewModel>(); // ViewModel is not a Control\n// after\ncontainerRegistry.RegisterDialog<MyDialogView, MyDialogViewModel>(); // MyDialogView : UserControl","handlingStrategy":"validation","validationCode":"var content = containerExtension.Resolve<object>(dialogName);\nif (content is not Avalonia.Controls.Control)\n    throw new InvalidOperationException($\"Dialog '{dialogName}' must resolve to an Avalonia.Controls.Control\");","typeGuard":"bool IsValidDialog(object view) => view is Avalonia.Controls.Control;","tryCatchPattern":null,"preventionTips":["Always register dialogs with RegisterDialog<TView, TViewModel>() where TView is an Avalonia Control","Add a startup smoke test that resolves every registered dialog name","Keep dialog view XAML Build Action set to AvaloniaXaml/Page"],"tags":["avalonia","dialogs","registration","type-mismatch"],"backgroundTag":"type-mismatch","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"}