dotnet/wpf · error · InvalidOperationException

Storyboard_PropertyPathObjectNotFound

Storyboard_PropertyPathObjectNotFound

Error message

SR.Format(SR.Storyboard_PropertyPathObjectNotFound, AccessorName(path, i-1), path.Path)

What it means

While validating an animation property path, Storyboard evaluates each intermediate segment with PropertyPath.GetItem; if any intermediate object (other than the root context) is null, VerifyPathIsAnimatable throws this InvalidOperationException naming the accessor that failed and the full path. It means the path could not be walked to a concrete object.

Solutions

  1. Fix the accessor segment reported in the exception (AccessorName) so it resolves to an existing, registered object.
  2. Call RegisterName for any names referenced in the path when building the storyboard in code.
  3. Simplify the property path; avoid segments that can evaluate to null.
  4. Ensure targeted template elements have names registered on the templated parent.
  5. Verify the root TargetName exists before Begin/Apply is called.

Example fix

// before
storyboard.SetValue(MediaTimeline.Storyboard.TargetProperty, new PropertyPath("(Canvas.Children)[5].(UIElement.Opacity)"));
// after
if (canvas.Children.Count > 5)
    storyboard.SetValue(MediaTimeline.Storyboard.TargetProperty, new PropertyPath("(Canvas.Children)[5].(UIElement.Opacity)"));
Defensive patterns

Strategy: validation

Validate before calling

static bool PathResolves(Storyboard sb, FrameworkElement root, string targetName, PropertyPath path)
{
    var target = root.FindName(targetName);
    if (target == null) return false;
    try { path.Evaluate(target); return true; } catch { return false; }
}

Type guard

bool HasRegisteredName(FrameworkElement root, string name) => root.FindName(name) != null;

Try / catch

try { storyboard.Begin(target); }
catch (InvalidOperationException ex) when (ex.Message.Contains("PropertyPath"))
{
    // validate and fix path segments, retry once
}

Prevention

When it happens

Trigger: A Storyboard.TargetProperty path whose intermediate segment resolves to null — e.g. a name in the path is not registered, a databound/indexed segment evaluates to null, or the root TargetName resolves to nothing so GetItem(i) returns null.

Common situations: Typos in x:Name inside the property path; targeting an element in a DataTemplate whose name is not registered; path segments like (Grid.Children)[0] returning null because the child was not added yet; path referencing a resource or bound value that failed to resolve.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

    //  not sufficient to mark an intermediate property read-only and
    //  not-animatable.  In fact, in the current design, it is impossible to
    //  be 100% sure that something will stay put.
    internal static void VerifyPathIsAnimatable(PropertyPath path)
    {
        object    intermediateObject = null;
        object    intermediateProperty = null; // Might be DependencyProperty, PropertyInfo, or PropertyDescriptor
        bool      checkingFrozenState = true;
        Freezable intermediateFreezable = null;

        for( int i=0; i < path.Length; i++ )
        {
            intermediateObject = path.GetItem(i);
            intermediateProperty = path.GetAccessor(i);

            if( intermediateObject == null )
            {
                Debug.Assert( i > 0, "The caller should not have set the PropertyPath context to a null object." );
                throw new InvalidOperationException(SR.Format(SR.Storyboard_PropertyPathObjectNotFound, AccessorName(path, i-1), path.Path ));
            }

            if( intermediateProperty == null )
            {
                // Would love to throw error with the name of the property we couldn't find,
                //  but that information is not exposed from the PropertyPath class.
                throw new InvalidOperationException(SR.Format(SR.Storyboard_PropertyPathPropertyNotFound, path.Path ));
            }

            // If the first property value is an immutable Freezable, then turn
            //  off the Frozen state checking - let's hope we can use the cloning
            //  mechanism for that case.
            // Index of zero is the path context object itself, one (that we're
            //  checking here) is the value of the first property.
            // Example: Property path "Background.Opacity" as applied to Button.
            //  Object 0 is the Button, object 1 is the brush.
            if( i == 1 )
            {

View on GitHub (pinned to 81131a70a4)