dotnet/wpf · error · InvalidOperationException

Storyboard_TargetNameNotDependencyObject

Storyboard_TargetNameNotDependencyObject

Error message

SR.Format(SR.Storyboard_TargetNameNotDependencyObject, targetName)

What it means

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.

Solutions

  1. Point Storyboard.TargetName at a FrameworkElement/FrameworkContentElement or other DependencyObject.
  2. Rename the non-DependencyObject resource so it is not confused with the target element.
  3. Register the intended visual target with x:Name and use that name.

Example fix

// before
<sys:String x:Key="Rect1">target</sys:String>
<DoubleAnimation Storyboard.TargetName="Rect1" .../>

// after
<Rectangle x:Name="Rect1"/>
<DoubleAnimation Storyboard.TargetName="Rect1" .../>
Defensive patterns

Strategy: validation

Validate before calling

bool ok = scope.FindName(targetName) is DependencyObject;

Type guard

static bool IsAnimatableTarget(INameScope scope, string name) => scope.FindName(name) is DependencyObject;

Try / catch

try { storyboard.Begin(fe, true); } catch (InvalidOperationException ex) { log.Error("Storyboard target is not a DependencyObject", ex); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/90e97fece1642673. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs:283

            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 the
    /// absense of name scope, use Framework(Content)Element.FindName which
    /// has its own complex set of rules for looking up name scopes.
    ///
    ///     This is a different set of rules than from that used to look up
    /// the TargetName.  BeginStoryboard name is registered with the template
    /// INameScope on a per-template basis.  So we look it up using
    /// INameScope.FindName().  This is a function completely different from

View on GitHub (pinned to 81131a70a4)