PrismLibrary/Prism · error · NullReferenceException
A dialog's content must be an Avalonia.Controls.Control
Error message
A dialog's content must be an Avalonia.Controls.Control
What it means
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.
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.
Example fix
// before containerRegistry.RegisterDialog<MyDialogViewModel, MyDialogViewModel>(); // ViewModel is not a Control // after containerRegistry.RegisterDialog<MyDialogView, MyDialogViewModel>(); // MyDialogView : UserControl
Defensive patterns
Strategy: validation
Validate before calling
var content = containerExtension.Resolve<object>(dialogName);
if (content is not Avalonia.Controls.Control)
throw new InvalidOperationException($"Dialog '{dialogName}' must resolve to an Avalonia.Controls.Control"); Type guard
bool IsValidDialog(object view) => view is Avalonia.Controls.Control;
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- A dialog's content must be a FrameworkElement
- A dialog's content must be a FrameworkElement
- A dialog's ViewModel must implement the IDialogAware…
- The Dialog ' ' must inherit from…
- ItemsControl's ItemsSource property is not empty. This…
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/635e959ee9248fcc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Avalonia/Prism.Avalonia/Dialogs/DialogService.cs:89
protected virtual IDialogWindow CreateDialogWindow(string name)
{
if (string.IsNullOrWhiteSpace(name))
return _containerExtension.Resolve<IDialogWindow>();
else
return _containerExtension.Resolve<IDialogWindow>(name);
}
/// <summary>
/// Configure <see cref="IDialogWindow"/> content.
/// </summary>
/// <param name="dialogName">The name of the dialog to show.</param>
/// <param name="window">The hosting window.</param>
/// <param name="parameters">The parameters to pass to the dialog.</param>
protected virtual void ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters)
{
var content = _containerExtension.Resolve<object>(dialogName);
if (!(content is Avalonia.Controls.Control dialogContent))
throw new NullReferenceException("A dialog's content must be an Avalonia.Controls.Control");
MvvmHelpers.AutowireViewModel(dialogContent);
if (!(dialogContent.DataContext is IDialogAware viewModel))
throw new NullReferenceException("A dialog's ViewModel must implement the IDialogAware interface");
ConfigureDialogWindowProperties(window, dialogContent, viewModel);
MvvmHelpers.ViewAndViewModelAction<IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));
}
/// <summary>
/// Configure <see cref="IDialogWindow"/> and <see cref="IDialogAware"/> events.
/// </summary>
/// <param name="dialogWindow">The hosting window.</param>
/// <param name="callback">The action to perform when the dialog is closed.</param>
protected virtual void ConfigureDialogWindowEvents(IDialogWindow dialogWindow, DialogCallback callback)
{View on GitHub (pinned to 358118cd64)