dotnet/wpf · error · InvalidOperationException
SR.Animation_NoTextChildren
Error message
SR.Animation_NoTextChildren
What it means
ColorAnimationUsingKeyFrames.AddText always throws InvalidOperationException (SR.Animation_NoTextChildren). Timelines have no text content model, so the IAddChild text path is intentionally unimplemented; the XML doc comment documents that text children are not supported.
Solutions
- Remove any text content inside the ColorAnimationUsingKeyFrames element in XAML
- Express values via key frame child elements instead of text
- If building content programmatically, use KeyFrames.Add rather than AddText
- Check for accidental characters/whitespace with non-trivial content between XAML tags
Example fix
// before (XAML) <ColorAnimationUsingKeyFrames>Red</ColorAnimationUsingKeyFrames> // after (XAML) <ColorAnimationUsingKeyFrames> <DiscreteColorKeyFrame KeyTime="0:0:1" Value="Red" /> </ColorAnimationUsingKeyFrames>
Defensive patterns
Strategy: validation
Validate before calling
// check before building XAML content bool hasTextContent = contentNode is text/whitespace-with-content; // reject before parse
Try / catch
try { addText(childText); }
catch (InvalidOperationException) { /* timelines never accept text; use key frames */ } Prevention
- Never place literal text inside animation elements in XAML
- Use key frame elements for all values
- Trim/inspect XAML for stray characters between tags
When it happens
Trigger: Calling AddText(string) directly, or XAML/content parsing that attempts to place a literal text string inside a <ColorAnimationUsingKeyFrames> element.
Common situations: Stray whitespace-laden text or a literal value typed inside the animation element in XAML; programmatic code treating the animation as a text-bearing content element.
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
- Animation_NoTextChildren
- Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
- SR.Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cc2b43ea712948cc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ColorAnimationUsingKeyFrames.cs:277
/// 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 ColorAnimationBase
/// <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)