{"record":{"id":"d83022551b75383a","repo":"dotnet/wpf","slug":"storyboard-namenotfound","errorCode":"Storyboard_NameNotFound","errorMessage":"SR.Format(SR.Storyboard_NameNotFound, targetName, nameScopeUsed.GetType().ToString())","messagePattern":"SR\\.Format\\(SR\\.Storyboard_NameNotFound, targetName, nameScopeUsed\\.GetType\\(\\)\\.ToString\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs","lineNumber":276,"sourceCode":"                namedObject = fe.FindName(targetName);\n                nameScopeUsed = fe;\n            }\n        }\n        else if( fce != null )\n        {\n            Debug.Assert( nameScope == null );\n            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","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs#L258-L294","documentation":"After finding the name scope in which to search, ResolveTargetName looks up TargetName; if the name is not registered in that scope (FindName returns null), WPF throws this InvalidOperationException including the target name and the type of the name scope searched.","triggerScenarios":"Setting Storyboard.TargetName to a name that does not exist in the resolved name scope — e.g. targeting an element in another template, a different x:Name, or an object registered after resolution runs.","commonSituations":"Storyboard defined in App.xaml or a shared template targeting a page-local element; typos in TargetName; elements loaded dynamically after the storyboard starts; names inside DataTemplate items that are virtualized.","solutions":["Ensure the TargetName exactly matches the x:Name of an element in the same name scope as the storyboard.","Move the storyboard into the same template/visual tree as its target element.","Use Storyboard.Target instead of TargetName when you already hold the DependencyObject reference in code.","Delay storyboard start (e.g. on Loaded event) until named elements exist."],"exampleFix":"// before\n<Storyboard>\n  <DoubleAnimation Storyboard.TargetName=\"Rect1\" .../> <!-- Rect1 not in this scope -->\n</Storyboard>\n\n// after\n<Grid>\n  <Rectangle x:Name=\"Rect1\"/>\n  <Storyboard x:Key=\"sb\">\n    <DoubleAnimation Storyboard.TargetName=\"Rect1\" .../>\n  </Storyboard>\n</Grid>","handlingStrategy":"validation","validationCode":"bool ok = targetElement.FindName(\"Rect1\") != null; // resolve before starting","typeGuard":"static bool NameResolvable(FrameworkElement scope, string name) => scope?.FindName(name) != null;","tryCatchPattern":"try { storyboard.Begin(fe, true); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"name\")) { log.Error($\"Storyboard target name missing: {ex.Message}\", ex); }","preventionTips":["Keep storyboards in the same scope as their TargetName elements","Spell-check TargetName against x:Name declarations","Start storyboards on Loaded when all named elements exist","Prefer Storyboard.Target with direct references in code"],"tags":["wpf","storyboard","namescope","xaml","name-resolution"],"backgroundTag":"entity-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}