{"record":{"id":"92776d98579a54b6","repo":"dotnet/wpf","slug":"storyboard-nonamescope","errorCode":"Storyboard_NoNameScope","errorMessage":"SR.Format(SR.Storyboard_NoNameScope, targetName)","messagePattern":"SR\\.Format\\(SR\\.Storyboard_NoNameScope, targetName\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs","lineNumber":270,"sourceCode":"            {\n                namedObject = ((FrameworkTemplate)nameScope).FindName(targetName, fe);\n                nameScopeUsed = nameScope;\n            }\n            else\n            {\n                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","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs#L252-L288","documentation":"Storyboard.ResolveTargetName needs an INameScope (or FrameworkElement/FrameworkContentElement) in which to look up TargetName. If none is supplied, it throws this InvalidOperationException: a name can only be resolved within some name scope.","triggerScenarios":"Calling Storyboard APIs (e.g. Storyboard.Begin, Seek, targeting resolution during ClockTreeWalkRecursive/ApplyMediaClock) with a null nameScope on a path that passes neither a FrameworkElement nor FrameworkContentElement — typically invoking with (object) overloads with a null target element.","commonSituations":"Calling Storyboard.Begin(null) or controlling a storyboard with a null containingObject; using storyboard targeting APIs from code without specifying the element that defines the names.","solutions":["Pass the FrameworkElement (or FrameworkContentElement) that contains the storyboard to Storyboard.Begin/Seek/etc.","Ensure TargetName resolution happens within the template/page that registered the target name.","Use the strongly typed overloads taking FrameworkElement instead of object."],"exampleFix":"// before\nstoryboard.Begin((object)null, IsControllable); // no name scope\n\n// after\nstoryboard.Begin(this /* containing FrameworkElement */, true);","handlingStrategy":"validation","validationCode":"bool ok = containingElement != null; // FrameworkElement that owns the name scope","typeGuard":"static bool HasNameScope(FrameworkElement fe) => fe != null;","tryCatchPattern":"try { storyboard.Begin(fe, isControllable); } catch (InvalidOperationException ex) { log.Error(\"No name scope for TargetName resolution\", ex); }","preventionTips":["Always pass the containing FrameworkElement to Storyboard control APIs","Avoid object-typed overloads with null","Start storyboards after the visual tree is loaded"],"tags":["wpf","storyboard","namescope","null-argument"],"backgroundTag":"null-argument","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"}