{"record":{"id":"90e97fece1642673","repo":"dotnet/wpf","slug":"storyboard-targetnamenotdependencyobject","errorCode":"Storyboard_TargetNameNotDependencyObject","errorMessage":"SR.Format(SR.Storyboard_TargetNameNotDependencyObject, targetName)","messagePattern":"SR\\.Format\\(SR\\.Storyboard_TargetNameNotDependencyObject, targetName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs","lineNumber":283,"sourceCode":"            namedObject = fce.FindName(targetName);\n            nameScopeUsed = fce;\n        }\n        else\n        {\n            throw new InvalidOperationException(\n                SR.Format(SR.Storyboard_NoNameScope, targetName));\n        }\n\n        if( namedObject == null )\n        {\n            throw new InvalidOperationException(\n                SR.Format(SR.Storyboard_NameNotFound, targetName, nameScopeUsed.GetType().ToString()));\n        }\n\n        targetObject = namedObject as DependencyObject;\n        if( targetObject == null )\n        {\n            throw new InvalidOperationException(SR.Format(SR.Storyboard_TargetNameNotDependencyObject, targetName ));\n        }\n\n        return targetObject;\n    }\n\n    /// <summary>\n    ///     Finds a BeginStoryboard with the given name, following the rules\n    /// governing Storyboard.  Returns null if not found.\n    /// </summary>\n    /// <remarks>\n    ///     If a name scope is given, look there and nowhere else.  In the\n    /// absense of name scope, use Framework(Content)Element.FindName which\n    /// has its own complex set of rules for looking up name scopes.\n    ///\n    ///     This is a different set of rules than from that used to look up\n    /// the TargetName.  BeginStoryboard name is registered with the template\n    /// INameScope on a per-template basis.  So we look it up using\n    /// INameScope.FindName().  This is a function completely different from","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs#L265-L301","documentation":"ResolveTargetName found an object registered under TargetName, but it is not a DependencyObject, so it cannot be an animation target. WPF throws this InvalidOperationException because animation targeting only works on DependencyObjects.","triggerScenarios":"TargetName resolves to a non-DependencyObject registered in the name scope — e.g. x:Name given to a plain CLR object in a ResourceDictionary, a string, or a non-visual item, then referenced as Storyboard.TargetName.","commonSituations":"Naming resources (like a converter or data object) in XAML and accidentally referencing that name in Storyboard.TargetName; FindName picking up items from a NameScope with mixed registrations.","solutions":["Point Storyboard.TargetName at a FrameworkElement/FrameworkContentElement or other DependencyObject.","Rename the non-DependencyObject resource so it is not confused with the target element.","Register the intended visual target with x:Name and use that name."],"exampleFix":"// before\n<sys:String x:Key=\"Rect1\">target</sys:String>\n<DoubleAnimation Storyboard.TargetName=\"Rect1\" .../>\n\n// after\n<Rectangle x:Name=\"Rect1\"/>\n<DoubleAnimation Storyboard.TargetName=\"Rect1\" .../>","handlingStrategy":"validation","validationCode":"bool ok = scope.FindName(targetName) is DependencyObject;","typeGuard":"static bool IsAnimatableTarget(INameScope scope, string name) => scope.FindName(name) is DependencyObject;","tryCatchPattern":"try { storyboard.Begin(fe, true); } catch (InvalidOperationException ex) { log.Error(\"Storyboard target is not a DependencyObject\", ex); }","preventionTips":["Only use Storyboard.TargetName on elements (DependencyObjects)","Avoid naming plain resources with names also used as targets","Verify FindName results before wiring them as animation targets"],"tags":["wpf","storyboard","xaml","type-mismatch"],"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"}