dotnet/wpf · error · InvalidOperationException

Storyboard_BeginStoryboardNoStoryboard

Storyboard_BeginStoryboardNoStoryboard

Error message

SR.Format(SR.Storyboard_BeginStoryboardNoStoryboard, BeginStoryboardName)

What it means

After resolving BeginStoryboardName via ResolveBeginStoryboardName, WPF reads the Storyboard property off the referenced BeginStoryboard. If it is null, GetStoryboard throws this InvalidOperationException because there is no storyboard to control.

Solutions

  1. Assign a Storyboard to the BeginStoryboard (in XAML nest <Storyboard> as its child; in code set keyedBeginStoryboard.Storyboard).
  2. Check that BeginStoryboardName references the intended BeginStoryboard, not an empty one.
  3. If building in code, populate the Storyboard before invoking any control action.

Example fix

// before
var begin = new BeginStoryboard();

// after
var begin = new BeginStoryboard { Storyboard = (Storyboard)FindResource("myStoryboard") };
Defensive patterns

Strategy: validation

Validate before calling

bool ok = beginStoryboard?.Storyboard != null;

Type guard

static bool HasStoryboard(BeginStoryboard b) => b?.Storyboard != null;

Try / catch

try { storyboard = action.GetStoryboard(fe, fce, scope); } catch (InvalidOperationException ex) { /* handle missing/misconfigured BeginStoryboard */ }

Prevention

When it happens

Trigger: BeginStoryboardName points at a valid BeginStoryboard instance whose Storyboard property is null — e.g. the BeginStoryboard was constructed in code as new BeginStoryboard() with no Storyboard assigned, before the control action fires.

Common situations: Programmatic construction of BeginStoryboard objects without setting the Storyboard; a default/placeholder BeginStoryboard left in a resource dictionary or template.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/ControllableStoryboardAction.cs:104

    }

    // Find a Storyboard object for this StoryboardAction to act on, using the
    //  given BeginStoryboardName to find a BeginStoryboard instance and use
    //  its Storyboard object reference.
    private Storyboard GetStoryboard( FrameworkElement fe, FrameworkContentElement fce, INameScope nameScope )
    {
        if( BeginStoryboardName == null )
        {
            throw new InvalidOperationException(SR.Storyboard_BeginStoryboardNameRequired);
        }

        BeginStoryboard keyedBeginStoryboard = Storyboard.ResolveBeginStoryboardName( BeginStoryboardName, nameScope, fe, fce );
        
        Storyboard storyboard = keyedBeginStoryboard.Storyboard;

        if( storyboard == null )
        {
            throw new InvalidOperationException(SR.Format(SR.Storyboard_BeginStoryboardNoStoryboard, BeginStoryboardName));
        }
        
        return storyboard;
    }

    private string     _beginStoryboardName = null;
}
}

View on GitHub (pinned to 81131a70a4)