{"record":{"id":"a4b980140f66a3a3","repo":"HandyOrg/HandyControl","slug":"the-dialog-is-not-a-derived-class-of-the-frameworkelement-a4b980","errorCode":null,"errorMessage":"The dialog is not a derived class of the FrameworkElement. ","messagePattern":"The dialog is not a derived class of the FrameworkElement\\. ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs","lineNumber":70,"sourceCode":"            }\n            catch (Exception e)\n            {\n                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":52,"sourceCodeEnd":78,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs#L52-L78","documentation":"Generic type-guard thrown by DialogExtension.GetViewModel when dialog.Content is not a FrameworkElement. The method needs to reach the view's DataContext to obtain the typed view model, and only a FrameworkElement exposes DataContext — any dialog whose content is a plain object, string, or non-Framework element fails this check before type matching even starts.","triggerScenarios":"Thrown at src/Shared/HandyControl_Shared/Tools/Extension/DialogExtension.cs:70 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the Dialog's Content is set to a FrameworkElement-derived view (UserControl, Window-content control, Page) before calling GetViewModel or Initialize","Set the ViewModel via dialog.DataContext or pass it explicitly if the content cannot be a FrameworkElement","Guard the call site with 'if (dialog.Content is FrameworkElement fe)' and surface a descriptive configuration error instead of letting the exception propagate"],"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"}