dotnet/wpf · error · ArgumentException
SR.Animation_ChildMustBeKeyFrame
Error message
SR.Animation_ChildMustBeKeyFrame
What it means
PointAnimationUsingKeyFrames.AddChild accepts only PointKeyFrame objects as XAML children; any other (or null) child causes this ArgumentException. WPF's key-frame animations are content-typed so the parser routes children through AddChild, which enforces the key-frame-only rule. The message literally states the child must be a key frame.
Solutions
- Use only PointKeyFrame-derived children: LinearPointKeyFrame, DiscretePointKeyFrame, SplinePointKeyFrame (or PointKeyFrame base elements).
- If converting from DoubleAnimationUsingKeyFrames, replace each Double*KeyFrame element with the corresponding Point*KeyFrame.
- Verify the XAML namespace maps to PresentationCore/WPF, not another framework's key frame types.
- If adding in code, call KeyFrames.Add(new LinearPointKeyFrame(...)) instead of AddChild.
Example fix
// before (XAML) <PointAnimationUsingKeyFrames> <LinearDoubleKeyFrame Value="10" KeyTime="0:0:1" /> </PointAnimationUsingKeyFrames> // after <PointAnimationUsingKeyFrames> <LinearPointKeyFrame Value="10,10" KeyTime="0:0:1" /> </PointAnimationUsingKeyFrames>
Defensive patterns
Strategy: validation
Validate before calling
if (child is PointKeyFrame kf) pointAnimationUsingKeyFrames.KeyFrames.Add(kf); else throw new ArgumentException($"Child must be a PointKeyFrame, got {child?.GetType().Name}"); Type guard
static bool IsPointKeyFrame(object o) => o is PointKeyFrame;
Try / catch
try { xamlReader.Load(xaml); }
catch (ArgumentException ex) when (ex.Message.Contains("key frame") || ex.Message.Contains("KeyFrame")) { /* fix child element type in XAML */ } Prevention
- Only nest PointKeyFrame-derived elements in PointAnimationUsingKeyFrames
- When copying key frame XAML between types, rename all key frame element types
- Prefer KeyFrames.Add in code over AddChild
When it happens
Trigger: Placing an element other than a PointKeyFrame (e.g. a raw Point, DoubleKeyFrame, or wrong-type key frame such as DoubleAnimationKeyFrame) inside a PointAnimationUsingKeyFrames element in XAML, or calling AddChild(null).
Common situations: Copy-pasting a DoubleAnimationUsingKeyFrames block and forgetting to change the key frame types to PointKeyFrame/LinearPointKeyFrame/DiscretePointKeyFrame/SplinePointKeyFrame; typo'd XAML namespace or element name inside the key frames collection.
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
- Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- Animation_ChildMustBeKeyFrame
- Animation_NoTextChildren
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9dbd60556def4cb2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/PointAnimationUsingKeyFrames.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)
{
PointKeyFrame keyFrame = child as PointKeyFrame;
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)