{"record":{"id":"afcbe74b62f365b6","repo":"PrismLibrary/Prism","slug":"the-viewmodel-does-not-implement-idialogaware","errorCode":null,"errorMessage":"The ViewModel does not implement IDialogAware","messagePattern":"The ViewModel does not implement IDialogAware","errorType":"exception","errorClass":"DialogException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs","lineNumber":200,"sourceCode":"        }\n    }\n\n    private static IDialogAware GetDialogController(View view)\n    {\n        if (view is IDialogAware viewAsDialogAware)\n        {\n            return viewAsDialogAware;\n        }\n        else if (view.BindingContext is null)\n        {\n            throw new DialogException(DialogException.NoViewModel);\n        }\n        else if (view.BindingContext is IDialogAware dialogAware)\n        {\n            return dialogAware;\n        }\n\n        throw new DialogException(DialogException.ImplementIDialogAware);\n    }\n}\n","sourceCodeStart":182,"sourceCodeEnd":203,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs#L182-L203","documentation":"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).","triggerScenarios":"ShowDialog/CloseDialogAsync on a dialog whose ViewModel is a plain class (e.g. just INotifyPropertyChanged) without implementing IDialogAware.","commonSituations":"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.","solutions":["Make the dialog ViewModel implement IDialogAware (including OnDialogOpened, CanCloseDialog, OnDialogClosed, RequestClose).","If the VM cannot implement IDialogAware, create a thin wrapper/dialog-specific ViewModel that does and delegates to the inner VM.","Verify the class actually implements all IDialogAware members so it satisfies the interface at runtime."],"exampleFix":"// before\npublic class MyDialogViewModel : BindableBase { ... }\n// after\npublic class MyDialogViewModel : BindableBase, IDialogAware\n{\n    public bool CanCloseDialog() => true;\n    public void OnDialogClosed() { }\n    public void OnDialogOpened(IDictionary<string, object> parameters) { }\n    public event EventHandler<IDialogResult> RequestClose;\n}","handlingStrategy":"type-guard","validationCode":"if (viewModel is not IDialogAware)\n    throw new InvalidOperationException($\"{viewModel.GetType().Name} must implement IDialogAware\");","typeGuard":"bool ImplementsDialogLifecycle(BindableBase vm) => vm is IDialogAware;","tryCatchPattern":"try { await dialogService.ShowDialogAsync(name); }\ncatch (DialogException ex) when (ex.Message.Contains(\"IDialogAware\"))\n{ logger.Error(ex, \"Dialog VM does not implement IDialogAware\"); }","preventionTips":["Make IDialogAware part of your dialog ViewModel base class/template.","Use a code-review checklist item: every dialog VM implements IDialogAware.","Add an archetype/T4 template or analyzer that enforces the interface on *DialogViewModel classes."],"tags":["prism","maui","dialogs","idialogaware"],"backgroundTag":"type-mismatch","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}