dotnet/wpf · error · InvalidOperationException
Storyboard_NoNameScope
Storyboard_NoNameScope
Error message
SR.Format(SR.Storyboard_NoNameScope, targetName)
What it means
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.
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.
Example fix
// before storyboard.Begin((object)null, IsControllable); // no name scope // after storyboard.Begin(this /* containing FrameworkElement */, true);
Defensive patterns
Strategy: validation
Validate before calling
bool ok = containingElement != null; // FrameworkElement that owns the name scope
Type guard
static bool HasNameScope(FrameworkElement fe) => fe != null;
Try / catch
try { storyboard.Begin(fe, isControllable); } catch (InvalidOperationException ex) { log.Error("No name scope for TargetName resolution", ex); } Prevention
- Always pass the containing FrameworkElement to Storyboard control APIs
- Avoid object-typed overloads with null
- Start storyboards after the visual tree is loaded
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SR.Format(SR.TargetNameNotFound, targetName)
- Storyboard_NameNotFound
- Storyboard_TargetNameNotAllowedInStyle
- annotation component
- ArgumentNullException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/92776d98579a54b6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs:270
{
namedObject = ((FrameworkTemplate)nameScope).FindName(targetName, fe);
nameScopeUsed = nameScope;
}
else
{
namedObject = fe.FindName(targetName);
nameScopeUsed = fe;
}
}
else if( fce != null )
{
Debug.Assert( nameScope == null );
namedObject = fce.FindName(targetName);
nameScopeUsed = fce;
}
else
{
throw new InvalidOperationException(
SR.Format(SR.Storyboard_NoNameScope, targetName));
}
if( namedObject == null )
{
throw new InvalidOperationException(
SR.Format(SR.Storyboard_NameNotFound, targetName, nameScopeUsed.GetType().ToString()));
}
targetObject = namedObject as DependencyObject;
if( targetObject == null )
{
throw new InvalidOperationException(SR.Format(SR.Storyboard_TargetNameNotDependencyObject, targetName ));
}
return targetObject;
}
View on GitHub (pinned to 81131a70a4)