{"record":{"id":"4068b5f45f835342","repo":"PrismLibrary/Prism","slug":"no-viewmodel-could-be-found","errorCode":null,"errorMessage":"No ViewModel could be found","messagePattern":"No ViewModel could be found","errorType":"exception","errorClass":"DialogException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs","lineNumber":193,"sourceCode":"                Parameters = result.Parameters,\n                Result = result.Result\n            };\n        }\n        finally\n        {\n            PageNavigationService.NavigationSource = PageNavigationSource.Device;\n        }\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":175,"sourceCodeEnd":203,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Dialogs/DialogServiceBase.cs#L175-L203","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set prism:ViewModelLocator.AutoWireViewModel=\"True\" on the dialog view's root element (or ensure it's enabled globally).","Make the dialog ViewModel implement IDialogAware and follow the View/ViewModel naming convention (MyDialogView -> MyDialogViewModel).","Register the dialog correctly via container.RegisterDialog<TView, TViewModel>() so the container constructs and binds the VM.","Verify the view's BindingContext isn't being cleared (e.g. by a style or x:Bind-style override) after creation."],"exampleFix":"// before\n<ContentPage xmlns=\"...\">\n// after\n<ContentPage xmlns:prism=\"http://prismlibrary.com\"\n             prism:ViewModelLocator.AutoWireViewModel=\"True\">","handlingStrategy":"validation","validationCode":"// before showing, verify wiring\nif (myDialogView.BindingContext is null)\n    throw new InvalidOperationException(\"Dialog VM not wired — check ViewModelLocator\");","typeGuard":"bool HasDialogViewModel(View v) => v.BindingContext is not null;","tryCatchPattern":"try { await dialogService.ShowDialogAsync(name); }\ncatch (DialogException ex) when (ex.Message.Contains(\"No ViewModel\"))\n{ logger.Error(ex, \"Dialog {Name} has no BindingContext/ViewModel\", name); }","preventionTips":["Always set prism:ViewModelLocator.AutoWireViewModel=\"True\" on dialog views.","Follow the View/ViewModel naming convention so auto-wiring resolves.","Create dialog views through the container/registry, never with `new`."],"tags":["prism","maui","dialogs","viewmodel-locator"],"backgroundTag":"missing-dependency","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"}