dotnet/wpf · error · InvalidOperationException
Storyboard_NameNotFound
Storyboard_NameNotFound
Error message
SR.Format(SR.Storyboard_NameNotFound, targetName, nameScopeUsed.GetType().ToString())
What it means
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.
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.
Example fix
// before
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Rect1" .../> <!-- Rect1 not in this scope -->
</Storyboard>
// after
<Grid>
<Rectangle x:Name="Rect1"/>
<Storyboard x:Key="sb">
<DoubleAnimation Storyboard.TargetName="Rect1" .../>
</Storyboard>
</Grid> Defensive patterns
Strategy: validation
Validate before calling
bool ok = targetElement.FindName("Rect1") != null; // resolve before starting Type guard
static bool NameResolvable(FrameworkElement scope, string name) => scope?.FindName(name) != null;
Try / catch
try { storyboard.Begin(fe, true); } catch (InvalidOperationException ex) when (ex.Message.Contains("name")) { log.Error($"Storyboard target name missing: {ex.Message}", ex); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Storyboard_TargetNameNotAllowedInStyle
- SR.Format(SR.CannotHavePropertyInTemplate…
- SR.Format(SR.NameNotFound, propertyValue.ChildName)
- SR.Format(SR.NameScopeDuplicateNamesNotAllowed, childName)
- SR.Format(SR.NameScopeNotFound, name, "register")
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d83022551b75383a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs:276
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;
}
/// <summary>
/// Finds a BeginStoryboard with the given name, following the rules
/// governing Storyboard. Returns null if not found.
/// </summary>
/// <remarks>
/// If a name scope is given, look there and nowhere else. In theView on GitHub (pinned to 81131a70a4)