PrismLibrary/Prism · error · ViewCreationException

Error creating dialog

Error message

Error creating dialog '{name}'

What it means

DialogServiceBase.ShowDialog wraps any failure that occurs while constructing and showing a dialog (view creation, container resolution, controller wiring) in a DialogException with the message "Error creating dialog '{name}'". The view is created via IDialogViewRegistry; if the registered view cannot be created or any setup step fails, this aggregate exception surfaces the underlying cause as InnerException.

Solutions

  1. Inspect InnerException for the root cause (often ViewCreationException or a DI resolution failure).
  2. Verify the dialog is registered via container.RegisterDialog<view, viewModel>(name) and the name matches exactly.
  3. Check that the dialog view's constructor dependencies are all registered in the container.
  4. Ensure module registrations run before ShowDialog is called (register modules at app startup).

Example fix

// before
container.RegisterDialog<UnknownView, MyViewModel>();
// after
container.RegisterDialog<MyDialogView, MyDialogViewModel>("MyDialog");
Defensive patterns

Strategy: try-catch

Validate before calling

if (!_container.IsRegistered<IDialogViewRegistry>() ||
    !DialogNames.Contains(name))
    throw new InvalidOperationException($"Dialog '{name}' is not registered");

Try / catch

try { await dialogService.ShowDialogAsync(name); }
catch (DialogException ex) { logger.Error(ex.InnerException ?? ex, "Dialog '{name}' failed to create", name); }

Prevention

When it happens

Trigger: Calling dialogService.ShowDialog(name, ...) where the dialog view registration throws (ViewCreationException), the DI container cannot resolve IDialogContainer/IDialogViewRegistry, the view's constructor throws, or required registrations are missing when a module loads lazily.

Common situations: Dialog registered with wrong view/viewModel pair; dialog view constructor has unresolvable constructor dependencies; module registrations not yet loaded when ShowDialog is invoked; typo in dialog name so registry returns null.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs:31

/// </summary>
public abstract class DialogServiceBase : IDialogService
{
    /// <inheritdoc/>
    public void ShowDialog(string name, IDialogParameters parameters, DialogCallback callback)
    {
        IDialogContainer? dialogModal = null;
        try
        {
            parameters = UriParsingHelper.GetSegmentParameters(name, parameters ?? new DialogParameters());

            var currentPage = GetCurrentPage();
            ArgumentNullException.ThrowIfNull(currentPage);
            var container = currentPage.GetContainerProvider();
            // This needs to be resolved when called as a Module could load any time
            // and register new dialogs
            var registry = container.Resolve<IDialogViewRegistry>();
            var view = registry.CreateView(container, UriParsingHelper.GetSegmentName(name)) as View 
                ?? throw new ViewCreationException(name, ViewType.Dialog);

            dialogModal = container.Resolve<IDialogContainer>();
            var dialogAware = GetDialogController(view);

            async Task DialogAware_RequestClose(IDialogResult outResult)
            {
                try
                {
                    var result = await CloseDialogAsync(outResult ?? new DialogResult(), currentPage, dialogModal);
                    if (result.Exception is DialogException de && de.Message == DialogException.CanCloseIsFalse)
                    {
                        return;
                    }

                    // DialogStack is updated when the container removes the overlay (e.g. DialogContainerPage.DoPop).
                    await callback.Invoke(result);
                    GC.Collect();
                }

View on GitHub (pinned to 358118cd64)