dotnet/wpf · error · ArgumentException
SR.Animation_ChildMustBeKeyFrame
Error message
SR.Animation_ChildMustBeKeyFrame
What it means
Int64AnimationUsingKeyFrames.AddChild throws ArgumentException when the supplied child is not a (non-null) Int64KeyFrame. Only key frames of the matching integer type are valid children of this timeline.
Solutions
- Use Int64KeyFrame-derived children (DiscreteInt64KeyFrame, LinearInt64KeyFrame, etc.).
- Correct the XAML child element type to match the animation.
- Prefer KeyFrames.Add with a typed key frame in code.
Example fix
// before <Int64AnimationUsingKeyFrames> <LinearInt32KeyFrame KeyTime="0:0:1" Value="100" /> </Int64AnimationUsingKeyFrames> // after <Int64AnimationUsingKeyFrames> <LinearInt64KeyFrame KeyTime="0:0:1" Value="100" /> </Int64AnimationUsingKeyFrames>
Defensive patterns
Strategy: validation
Validate before calling
if (child is not Int64KeyFrame)
throw new ArgumentException("Children of Int64AnimationUsingKeyFrames must be Int64KeyFrame instances", nameof(child)); Type guard
bool IsInt64KeyFrame(object o) => o is Int64KeyFrame;
Try / catch
try { animation.AddChild(child); }
catch (ArgumentException ex) when (ex.ParamName == "child") {
// swap in the correctly typed Int64KeyFrame
} Prevention
- Match key frame child types to the animation value type (Int64 vs Int32)
- Check markup after refactoring animation value types
- Use KeyFrames.Add in code for compile-time type safety
When it happens
Trigger: XAML declaring a child that is not an Int64KeyFrame inside <Int64AnimationUsingKeyFrames>, or programmatic AddChild with an incompatible object.
Common situations: Mixing key frame types across animations (e.g. Int32KeyFrame inside an Int64 animation); XAML paste errors.
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/62972c3fe36038a3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Int64AnimationUsingKeyFrames.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)
{
Int64KeyFrame keyFrame = child as Int64KeyFrame;
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)