dotnet/wpf · error · ArgumentException
SR.Animation_ChildMustBeKeyFrame
Error message
SR.Animation_ChildMustBeKeyFrame
What it means
ArgumentException thrown by Int32AnimationUsingKeyFrames.AddChild (the IAddChild path used for XAML markup children): the child object is not an Int32KeyFrame, and key-frame animations only accept key frames of their specific type as direct children.
Solutions
- Use Int32KeyFrame-derived children (e.g. Int32KeyFrame subclasses like DiscreteInt32KeyFrame, LinearInt32KeyFrame) inside the animation.
- Fix XAML markup so the child element matches the animation's key frame type.
- If adding programmatically, call KeyFrames.Add with a typed Int32KeyFrame instead of AddChild.
Example fix
// before <Int32AnimationUsingKeyFrames> <Int32Animation ... /> </Int32AnimationUsingKeyFrames> // after <Int32AnimationUsingKeyFrames> <LinearInt32KeyFrame KeyTime="0:0:1" Value="100" /> </Int32AnimationUsingKeyFrames>
Defensive patterns
Strategy: validation
Validate before calling
if (child is not Int32KeyFrame)
throw new ArgumentException("Children of Int32AnimationUsingKeyFrames must be Int32KeyFrame instances", nameof(child)); Type guard
bool IsInt32KeyFrame(object o) => o is Int32KeyFrame;
Try / catch
try { animation.AddChild(child); }
catch (ArgumentException ex) when (ex.ParamName == "child") {
// replace with the correct typed key frame
} Prevention
- Keep key frame child types matched to the animation's value type
- Avoid hand-editing generated XAML animation markup without type checking
- Prefer KeyFrames.Add over AddChild in code so the compiler enforces the type
When it happens
Trigger: Declaring a non-key-frame child element inside <Int32AnimationUsingKeyFrames> in XAML, or calling AddChild with an object that is not an Int32KeyFrame.
Common situations: XAML typo or wrong child element (e.g. putting a plain Int32Animation or a DoubleKeyFrame inside an Int32 key-frame animation); copy-paste between differently-typed animations.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- Animation_AnimationTimelineTypeMismatch
- Animation_ChildMustBeKeyFrame
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/63d3a4b374a4bf06.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Int32AnimationUsingKeyFrames.cs:227
WritePostscript();
}
/// <summary>
/// Implemented to allow KeyFrames to be direct children
/// of KeyFrameAnimations in markup.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void AddChild(object child)
{
Int32KeyFrame keyFrame = child as Int32KeyFrame;
if (keyFrame != null)
{
KeyFrames.Add(keyFrame);
}
else
{
throw new ArgumentException(SR.Animation_ChildMustBeKeyFrame, nameof(child));
}
}
/// <summary>
/// Adds a text string as a child of this KeyFrameAnimation.
/// </summary>
/// <param name="childText">
/// The text to add.
/// </param>
/// <remarks>
/// A KeyFrameAnimation does not accept text as a child, so this method will
/// raise an InvalididOperationException unless a derived class has
/// overridden the behavior to add text.
/// </remarks>
/// <exception cref="ArgumentNullException">The childText parameter is
/// null.</exception>
void IAddChild.AddText(string childText)
{View on GitHub (pinned to 81131a70a4)