PrismLibrary/Prism · error · NullReferenceException

A dialog's content must be a FrameworkElement

Error message

A dialog's content must be a FrameworkElement

What it means

Prism's Uno DialogService resolves the view registered for the dialog name and requires the resolved object to be a FrameworkElement so it can wire up the dialog window content. If the container resolves anything else (or null), it throws this NullReferenceException. This is a registration/usage contract: dialogs must be registered as views (FrameworkElement-based) for dialog service lookups to succeed.

Solutions

  1. Register the dialog view with RegisterDialog<MyDialogView, MyDialogViewModel>("name") so Resolve<object>(name) yields a FrameworkElement.
  2. Ensure the dialog name passed to ShowDialog matches the registered name exactly.
  3. Make the dialog a UserControl (or other FrameworkElement) rather than a plain class or ViewModel.
  4. Verify the dialog module/assembly is actually loaded and registered before ShowDialog is called (initialize the module first).

Example fix

// before
containerRegistry.RegisterDialog<MyDialogViewModel>(); // resolves a non-FrameworkElement

// after
containerRegistry.RegisterDialog<MyDialogView, MyDialogViewModel>();
Defensive patterns

Strategy: type-guard

Validate before calling

// before calling ShowDialog
var content = containerProvider.Resolve<object>(dialogName);
if (content is not FrameworkElement)
    throw new InvalidOperationException($"Dialog '{dialogName}' must be registered as a FrameworkElement view.");

Type guard

static bool IsRegisteredDialogView(IContainerProvider container, string name) =>
    container.Resolve<object>(name) is FrameworkElement;

Try / catch

try
{
    dialogService.ShowDialog(dialogName, parameters, callback);
}
catch (NullReferenceException ex) when (ex.Message.Contains("must be a FrameworkElement"))
{
    logger.LogError(ex, "Dialog {Dialog} not registered as a view", dialogName);
}

Prevention

When it happens

Trigger: Calling IDialogService.ShowDialog(name, ...) where the type registered under `name` in the container (via RegisterDialog or container registration) is not a FrameworkElement, or resolving an unregistered name returns null/non-FrameworkElement.

Common situations: Registering a ViewModel (or plain class) instead of a View with RegisterDialog; forgetting to call RegisterDialog and having a stale/incorrect container registration; a custom registration that maps the dialog name to a non-UI type; migration from another container where Resolve<object>(name) semantics differ.

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/910ffcea4cc6f676. Report an issue: GitHub.

Appendix: source

Thrown at src/Uno/Prism.Uno/Dialogs/DialogService.cs:59

                var str = ex.ToString();
                await callback.Invoke(ex);
            }
        }

        IDialogWindow CreateDialogWindow(string? name)
        {
            if (string.IsNullOrWhiteSpace(name))
                return _containerProvider.Resolve<IDialogWindow>();
            else
                return _containerProvider.Resolve<IDialogWindow>(name);
        }

        void ConfigureDialogWindowContent(string dialogName, IDialogWindow window, IDialogParameters parameters)
        {
            var content = _containerProvider.Resolve<object>(dialogName);
            if (content is not FrameworkElement dialogContent)
            {
                throw new NullReferenceException("A dialog's content must be a FrameworkElement");
            }

            MvvmHelpers.AutowireViewModel(content);

            if (dialogContent.DataContext is not IDialogAware viewModel)
            {
                throw new NullReferenceException($"A dialog's ViewModel must implement the IDialogAware interface ({dialogContent.DataContext})");
            }

            DialogService.ConfigureDialogWindowProperties(window, dialogContent, viewModel);

            MvvmHelpers.ViewAndViewModelAction<IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));
        }

        void ConfigureDialogWindowEvents(IDialogWindow contentDialog, DialogCallback callback)
        {
            IDialogResult? result = null;

View on GitHub (pinned to 358118cd64)