dotnet/wpf · error · InvalidOperationException

SR.Animation_NoTextChildren

Error message

SR.Animation_NoTextChildren

What it means

WPF timeline/key-frame animation objects do not accept text content. AddText is the Advanced (code-generated) content-addition hook; because Timelines have no textual content model, any call throws InvalidOperationException with SR.Animation_NoTextChildren. The library throws it to signal a programmatic misuse of the content-building API surface rather than a data problem.

Solutions

  1. Remove the text child from the animation element; animations accept only key frames/timelines as children
  2. If you meant to configure the animation, set properties (e.g. Duration, KeyFrames) instead of supplying text
  3. In custom code, never invoke AddText on Timeline-derived objects; call AddChild with a Timeline child

Example fix

// before
new DoubleAnimationUsingKeyFrames(); anim.AddText("0;1;2");
// after
var anim = new DoubleAnimationUsingKeyFrames();
anim.KeyFrames.Add(new LinearDoubleKeyFrame(0));
anim.KeyFrames.Add(new LinearDoubleKeyFrame(1));
Defensive patterns

Strategy: validation

Validate before calling

if (anim is Timeline) throw new ArgumentException("Animations do not accept text children; supply Timeline children instead.");

Type guard

bool IsTimeline(object o) => o is System.Windows.Media.Animation.Timeline;

Prevention

When it happens

Trigger: Calling the protected AddText(string) method on a generated animation class (e.g. a DoubleAnimationUsingKeyFrames subclass built from the codegen Elements template), typically via XAML/object-model infrastructure that routes text children into AddChild/AddText.

Common situations: XAML compiler or markup writer emitting text into an animation element (e.g. <DoubleAnimationUsingKeyFrames>some text</...>); custom serialization code that treats animations like text-content controls; tooling that copies children between content models.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationUsingKeyFramesTemplate.cs:355

                                    /// WritePreamble() or WritePostscript().  It also doesn't throw an
                                    /// ArgumentNullException if the childText parameter is null.  These tasks
                                    /// are performed by the interface implementation.  Therefore, it's OK
                                    /// for a derived class to override this method and call the base
                                    /// class implementation only if they determine that it's the right
                                    /// course of action.  The derived class can rely on KeyFrameAnimation's
                                    /// implementation of IAddChild.AddChild or implement their own
                                    /// following the Freezable pattern since that would be a public
                                    /// method.
                                    /// </remarks>
                                    /// <param name="childText">A string representing the child text that
                                    /// should be added.  If this is a KeyFrameAnimation an exception will be
                                    /// thrown.</param>
                                    /// <exception cref="InvalidOperationException">Timelines have no way
                                    /// of adding text.</exception>
                                    [EditorBrowsable(EditorBrowsableState.Advanced)]
                                    protected virtual void AddText(string childText)
                                    {
                                        throw new InvalidOperationException(SR.Animation_NoTextChildren);
                                    }
                                    
                                    #endregion
                                    
                                    #region [[instance.TypeName]]AnimationBase
                                    
                                    /// <summary>
                                    /// Calculates the value this animation believes should be the current value for the property.
                                    /// </summary>
                                    /// <param name="defaultOriginValue">
                                    /// This value is the suggested origin value provided to the animation
                                    /// to be used if the animation does not have its own concept of a
                                    /// start value. If this animation is the first in a composition chain
                                    /// this value will be the snapshot value if one is available or the
                                    /// base property value if it is not; otherise this value will be the 
                                    /// value returned by the previous animation in the chain with an 
                                    /// animationClock that is not Stopped.
                                    /// </param>

View on GitHub (pinned to 81131a70a4)