PrismLibrary/Prism · error · DialogException

The ViewModel does not implement IDialogAware

Error message

The ViewModel does not implement IDialogAware

What it means

After locating the dialog view's BindingContext, GetDialogController requires it to implement IDialogAware so Prism can drive the dialog lifecycle (OnAppearing/RequestClose etc.). If the ViewModel is present but does not implement IDialogAware, Prism throws DialogException (ImplementIDialogAware).

Solutions

  1. Make the dialog ViewModel implement IDialogAware (including OnDialogOpened, CanCloseDialog, OnDialogClosed, RequestClose).
  2. If the VM cannot implement IDialogAware, create a thin wrapper/dialog-specific ViewModel that does and delegates to the inner VM.
  3. Verify the class actually implements all IDialogAware members so it satisfies the interface at runtime.

Example fix

// before
public class MyDialogViewModel : BindableBase { ... }
// after
public class MyDialogViewModel : BindableBase, IDialogAware
{
    public bool CanCloseDialog() => true;
    public void OnDialogClosed() { }
    public void OnDialogOpened(IDictionary<string, object> parameters) { }
    public event EventHandler<IDialogResult> RequestClose;
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (viewModel is not IDialogAware)
    throw new InvalidOperationException($"{viewModel.GetType().Name} must implement IDialogAware");

Type guard

bool ImplementsDialogLifecycle(BindableBase vm) => vm is IDialogAware;

Try / catch

try { await dialogService.ShowDialogAsync(name); }
catch (DialogException ex) when (ex.Message.Contains("IDialogAware"))
{ logger.Error(ex, "Dialog VM does not implement IDialogAware"); }

Prevention

When it happens

Trigger: ShowDialog/CloseDialogAsync on a dialog whose ViewModel is a plain class (e.g. just INotifyPropertyChanged) without implementing IDialogAware.

Common situations: Reusing an existing page ViewModel as a dialog ViewModel without adding IDialogAware; migrating dialogs from older Prism versions where IDialogAware members changed; forgetting to implement the interface after renaming the VM class.

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


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

Appendix: source

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

        }
    }

    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)