dotnet/wpf · error · InvalidOperationException

Storyboard_StoryboardReferenceRequired

Storyboard_StoryboardReferenceRequired

Error message

SR.Storyboard_StoryboardReferenceRequired

What it means

BeginStoryboard.Seal throws InvalidOperationException (SR.Storyboard_StoryboardReferenceRequired) when the Storyboard property is still null (or its reference could not be resolved) at seal time. Since sealing forbids further changes, an unresolved Storyboard can never be fixed later, so the error matches the one Begin would throw.

Solutions

  1. Ensure the Storyboard property is set to a valid Storyboard instance before the trigger collection is sealed.
  2. Fix the resource key in XAML so the Storyboard reference resolves (verify StaticResource name and scope).
  3. Define the Storyboard resource earlier in the visual tree (e.g. in Window/Application resources) so resolution succeeds.

Example fix

// before
<BeginStoryboard Name="begin"/> <!-- Storyboard missing -->
// after
<BeginStoryboard Name="begin" Storyboard="{StaticResource FadeInStoryboard}"/>
Defensive patterns

Strategy: validation

Validate before calling

if (beginStoryboard.Storyboard == null)
    throw new InvalidOperationException("BeginStoryboard.Storyboard must be set before sealing");

Try / catch

try { actions.Seal(); }
catch (InvalidOperationException ex) { /* log missing Storyboard reference; fix resource key */ }

Prevention

When it happens

Trigger: Sealing a BeginStoryboard (via sealing the containing TriggerActions collection) whose Storyboard property is null, e.g. a StaticResource lookup that failed so the storyboard reference never resolved.

Common situations: XAML Triggers where the Storyboard StaticResource/DynamicResource reference is misspelled or the resource is defined after/outside the reachable scope.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/BeginStoryboard.cs:139

    // Bug #1329664 workaround to make beta 2
    // Remove thread affinity when sealed, but before doing that, snapshot the
    //  current Storyboard value and remove *its* thread affinity too.
    internal override void Seal()
    {
        if( !IsSealed )
        {
            // Gets our Storyboard value.  This value may have come from a
            //  ResourceReferenceExpression or might have been a deferred
            //  reference that has since been realized.
            Storyboard snapshot = GetValue(StoryboardProperty) as Storyboard;

            if( snapshot == null )
            {
                // This is the same error thrown by Begin if the Storyboard
                //  property couldn't be resolved at Begin time.  Since we're
                //  not allowing changes after this point, lack of resolution
                //  here means the same thing.
                throw new InvalidOperationException(SR.Storyboard_StoryboardReferenceRequired);
            }
            
            // We're planning to break our thread affinity - we also need to
            //  make sure the Storyboard can also be used accross threads.
            if(!snapshot.CanFreeze)
            {
                throw new InvalidOperationException(SR.Storyboard_UnableToFreeze);
            }
            if(!snapshot.IsFrozen)
            {
                snapshot.Freeze();
            }

            // Promote that snapshot into a local value.  This is a no-op if it
            //  was a deferred reference or local Storyboard, but if it came from a 
            //  ResourceReferenceExpression it will replace the Expression object
            //  with a snapshot of its current value.
            Storyboard = snapshot;

View on GitHub (pinned to 81131a70a4)