PrismLibrary/Prism · error · DialogException

No ViewModel could be found

Error message

No ViewModel could be found

What it means

GetDialogController finds the IDialogAware controller for a dialog: it checks the view itself, then the view's BindingContext. If BindingContext is null, no ViewModel exists, so Prism throws DialogException (NoViewModel, message "No ViewModel could be found"). Prism requires every dialog to have an IDialogAware implementer to manage open/close lifecycle.

Solutions

  1. Set prism:ViewModelLocator.AutoWireViewModel="True" on the dialog view's root element (or ensure it's enabled globally).
  2. Make the dialog ViewModel implement IDialogAware and follow the View/ViewModel naming convention (MyDialogView -> MyDialogViewModel).
  3. Register the dialog correctly via container.RegisterDialog<TView, TViewModel>() so the container constructs and binds the VM.
  4. Verify the view's BindingContext isn't being cleared (e.g. by a style or x:Bind-style override) after creation.

Example fix

// before
<ContentPage xmlns="...">
// after
<ContentPage xmlns:prism="http://prismlibrary.com"
             prism:ViewModelLocator.AutoWireViewModel="True">
Defensive patterns

Strategy: validation

Validate before calling

// before showing, verify wiring
if (myDialogView.BindingContext is null)
    throw new InvalidOperationException("Dialog VM not wired — check ViewModelLocator");

Type guard

bool HasDialogViewModel(View v) => v.BindingContext is not null;

Try / catch

try { await dialogService.ShowDialogAsync(name); }
catch (DialogException ex) when (ex.Message.Contains("No ViewModel"))
{ logger.Error(ex, "Dialog {Name} has no BindingContext/ViewModel", name); }

Prevention

When it happens

Trigger: Showing/closing a dialog whose view has no BindingContext — e.g. the ViewModel was not auto-wired (missing AutoViewModelLocator / ViewModelLocator.AutoWireViewModel), or the view was created without the container wiring the VM.

Common situations: Dialog view created manually with new instead of through the container/registry; prism:ViewModelLocator.AutoWireViewModel="True" omitted; AutoWireViewModels disabled in startup; the view type and VM name don't follow Prism's convention so binding fails silently.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

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

                Parameters = result.Parameters,
                Result = result.Result
            };
        }
        finally
        {
            PageNavigationService.NavigationSource = PageNavigationSource.Device;
        }
    }

    private static IDialogAware GetDialogController(View view)
    {
        if (view is IDialogAware viewAsDialogAware)
        {
            return viewAsDialogAware;
        }
        else if (view.BindingContext is null)
        {
            throw new DialogException(DialogException.NoViewModel);
        }
        else if (view.BindingContext is IDialogAware dialogAware)
        {
            return dialogAware;
        }

        throw new DialogException(DialogException.ImplementIDialogAware);
    }
}

View on GitHub (pinned to 358118cd64)