{"record":{"id":"85eb04bea41607f1","repo":"HandyOrg/HandyControl","slug":"the-view-model-of-the-dialog-is-not-the-typeof-tviewmodel-85eb04","errorCode":null,"errorMessage":"The view model of the dialog is not the {typeof(TViewModel)} type or its derived class. ","messagePattern":"The view model of the dialog is not the (.+?) type or its derived class\\. ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs","lineNumber":73,"sourceCode":"                tcs.TrySetException(e);\n            }\n        }\n    }\n\n    public static Dialog Initialize<TViewModel>(this Dialog dialog, Action<TViewModel> configure)\n    {\n        configure?.Invoke(dialog.GetViewModel<TViewModel>());\n\n        return dialog;\n    }\n\n    public static TViewModel GetViewModel<TViewModel>(this Dialog dialog)\n    {\n        if (!(dialog.Content is FrameworkElement frameworkElement))\n            throw new InvalidOperationException(\"The dialog is not a derived class of the FrameworkElement. \");\n\n        if (!(frameworkElement.DataContext is TViewModel viewModel))\n            throw new InvalidOperationException($\"The view model of the dialog is not the {typeof(TViewModel)} type or its derived class. \");\n\n        return viewModel;\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":78,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs#L55-L78","documentation":"Generic type-guard thrown by DialogExtension.GetViewModel when the view's DataContext does exist but is not of type TViewModel (nor a subclass). The FrameworkElement check has already passed; the failure is purely a mismatch between the requested generic type and the view's actual DataContext — typically a wrong generic argument in Initialize<TViewModel> or a view wired to a different view model class.","triggerScenarios":"Thrown at src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs:73 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Match the generic argument to the view's actual DataContext type, e.g. dialog.Initialize<MyActualViewModel>(vm => ...)","Set the view's DataContext explicitly to the intended TViewModel instance (or use the dialog's ViewModel property) before calling Initialize/GetViewModel","At the call site, check 'if (frameworkElement.DataContext is TViewModel vm)' first and report a clear configuration error instead of relying on the throw"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}