{"record":{"id":"78fbb4a31686fcab","repo":"dotnet/wpf","slug":"sr-mustbeframeworkderived","errorCode":null,"errorMessage":"SR.MustBeFrameworkDerived","messagePattern":"SR\\.MustBeFrameworkDerived","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs","lineNumber":66,"sourceCode":"    {\n        #region Constructors\n\n        internal FrameworkObject(DependencyObject d)\n        {\n            // [code should be identical to Reset(d)]\n            _do = d;\n\n            _fe = d as FrameworkElement;\n            _fce = d as FrameworkContentElement;\n        }\n\n        internal FrameworkObject(DependencyObject d, bool throwIfNeither)\n            : this(d)\n        {\n            if (throwIfNeither && _fe == null && _fce == null)\n            {\n                object arg = (d != null) ? (object)d.GetType() : (object)\"NULL\";\n                throw new InvalidOperationException(SR.Format(SR.MustBeFrameworkDerived, arg));\n            }\n        }\n\n        internal FrameworkObject(FrameworkElement fe, FrameworkContentElement fce)\n        {\n            _fe = fe;\n            _fce = fce;\n\n            if (fe != null)\n                _do = fe;\n            else\n                _do = fce;\n        }\n\n        internal void Reset(DependencyObject d)\n        {\n            _do = d;\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs#L48-L84","documentation":"FrameworkObject wraps a DependencyObject as either a FrameworkElement or FrameworkContentElement; when neither applies and the caller asked to throw (throwIfNeither), it throws this InvalidOperationException. WPF logical-tree APIs require framework-level objects; plain DependencyObjects (e.g. Freezables or bare DependencyObjects) cannot participate.","triggerScenarios":"Constructing FrameworkObject with throwIfNeither:true for a DependencyObject that is neither a FrameworkElement nor FrameworkContentElement (or for null).","commonSituations":"Passing a Freezable (Brush, Geometry), Animation, or a plain DependencyObject to APIs that walk the logical tree; calling tree-walking helpers on non-framework nodes; accidentally passing null.","solutions":["Only pass FrameworkElement or FrameworkContentElement instances to framework-tree APIs","For non-framework DependencyObjects, operate on them directly instead of via FrameworkObject","Check the type first: if (obj is FrameworkElement fe) ... else if (obj is FrameworkContentElement fce) ...","Guard against null before calling"],"exampleFix":"// before\nvar fo = new FrameworkObject(depObj, true);\n// after\nif (depObj is FrameworkElement || depObj is FrameworkContentElement)\n{ var fo = new FrameworkObject(depObj, true); }","handlingStrategy":"type-guard","validationCode":"if (d != null && !(d is FrameworkElement) && !(d is FrameworkContentElement)) throw new InvalidOperationException(\"Requires FrameworkElement/ContentElement\");","typeGuard":"static bool IsFrameworkObject(DependencyObject d) => d is FrameworkElement || d is FrameworkContentElement;","tryCatchPattern":"try { var fo = new FrameworkObject(d, true); } catch (InvalidOperationException) { /* handle non-framework DependencyObject */ }","preventionTips":["Guard with `is FrameworkElement`/`is FrameworkContentElement` before framework-tree APIs","Never pass Freezables or plain DependencyObjects to logical-tree helpers","Null-check before constructing FrameworkObject"],"tags":["wpf","framework-element","type-mismatch","logical-tree"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}