dotnet/wpf · error · ArgumentException
SR.Animation_ChildMustBeKeyFrame
Error message
SR.Animation_ChildMustBeKeyFrame
What it means
ArgumentException thrown by Point3DAnimationUsingKeyFrames.AddChild (the IAddChild path used for XAML markup children): the child object is not a Point3DKeyFrame, and key-frame animations only accept key frames of their specific type as direct children.
Solutions
- Use Point3D key frames such as LinearPoint3DKeyFrame or SplinePoint3DKeyFrame as children
- Type-check the child (is Point3DKeyFrame) before calling AddChild
- Add frames via KeyFrames.Add in code
Example fix
// before anim.AddChild(new Point3D(1,2,3)); // after anim.KeyFrames.Add(new LinearPoint3DKeyFrame(new Point3D(1,2,3), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));
Defensive patterns
Strategy: type-guard
Validate before calling
if (child is Point3DKeyFrame kf) animation.KeyFrames.Add(kf);
Type guard
bool IsPoint3DKeyFrame(object c) => c is Point3DKeyFrame;
Try / catch
try { animation.AddChild(child); }
catch (ArgumentException ex) when (ex.ParamName == nameof(child)) { /* use a Point3DKeyFrame child instead */ } Prevention
- Only nest Point3D key frames in Point3DAnimationUsingKeyFrames
- Wrap raw Point3D values in Linear/Discrete/Spline key frames
- Prefer the typed KeyFrames.Add API in code
When it happens
Trigger: Calling AddChild with null or a non-Point3DKeyFrame object, or XAML nesting an unsupported element inside <Point3DAnimationUsingKeyFrames>.
Common situations: Wrong key-frame type in XAML (e.g. DoubleKeyFrame), plain values as children, or code passing arbitrary objects to AddChild.
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.Timing_ChildMustBeTimeline
- Animation_ChildMustBeKeyFrame
- Animation_ChildMustBeKeyFrame
- Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ccbb4c50c4337d5b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Point3DAnimationUsingKeyFrames.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)
{
Point3DKeyFrame keyFrame = child as Point3DKeyFrame;
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)