dotnet/wpf · error · InvalidOperationException
Animation_NoTextChildren
Animation_NoTextChildren
Error message
SR.Animation_NoTextChildren (Animation_NoTextChildren)
What it means
AddText is called on a timeline (here BooleanAnimationUsingKeyFrames) whose content model does not support text children. Timelines cannot contain text, so the default implementation unconditionally throws InvalidOperationException. This API exists only as part of the IAddChild pattern and is not meant to succeed for animations.
Solutions
- Remove the text content from inside the animation element in XAML.
- Express values as key frames: <DiscreteBooleanKeyFrame Value="True" KeyTime="..."/>.
- If parsing XAML programmatically, ignore/strip text nodes inside animation elements before feeding IAddChild.
Example fix
// before (XAML) <BooleanAnimationUsingKeyFrames> True </BooleanAnimationUsingKeyFrames> // after <BooleanAnimationUsingKeyFrames> <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0"/> </BooleanAnimationUsingKeyFrames>
Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(childText))
throw new InvalidOperationException("Timelines accept no text children; use key frames"); Type guard
static bool HasNoTextContent(XElement el) => !el.Nodes().OfType<XText>().Any(t => !string.IsNullOrWhiteSpace(t.Value));
Try / catch
try { animation.AddText(text); }
catch (InvalidOperationException) { /* strip text nodes / convert to key frames */ } Prevention
- Never place raw text inside timeline elements in XAML.
- Strip whitespace/text nodes when parsing animation markup programmatically.
- Express all values through key frame child elements.
When it happens
Trigger: XAML containing raw text between <BooleanAnimationUsingKeyFrames> tags (e.g. stray whitespace-handling edge text or accidental characters); code calling AddText("...") directly via IAddChild.
Common situations: Typing a value directly inside the animation element in XAML instead of nesting a key frame; XAML tools emitting literal text content; misunderstanding the content model and putting values inline.
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
- SR.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/bdfa2a2996f95fdc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/BooleanAnimationUsingKeyFrames.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 BooleanAnimationBase
/// <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)