{"record":{"id":"9dbd60556def4cb2","repo":"dotnet/wpf","slug":"sr-animation-childmustbekeyframe-9dbd60","errorCode":null,"errorMessage":"SR.Animation_ChildMustBeKeyFrame","messagePattern":"SR\\.Animation_ChildMustBeKeyFrame","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/PointAnimationUsingKeyFrames.cs","lineNumber":227,"sourceCode":"            WritePostscript();\n        }\n\n        /// <summary>\n        /// Implemented to allow KeyFrames to be direct children\n        /// of KeyFrameAnimations in markup.\n        /// </summary>\n        [EditorBrowsable(EditorBrowsableState.Advanced)]\n        protected virtual void AddChild(object child)\n        {\n            PointKeyFrame keyFrame = child as PointKeyFrame;\n\n            if (keyFrame != null)\n            {\n                KeyFrames.Add(keyFrame);\n            }\n            else\n            {        \n                throw new ArgumentException(SR.Animation_ChildMustBeKeyFrame, nameof(child));\n            }\n        }\n\n        /// <summary>\n        /// Adds a text string as a child of this KeyFrameAnimation.\n        /// </summary>\n        /// <param name=\"childText\">\n        /// The text to add.\n        /// </param>\n        /// <remarks>\n        /// A KeyFrameAnimation does not accept text as a child, so this method will\n        /// raise an InvalididOperationException unless a derived class has\n        /// overridden the behavior to add text.\n        /// </remarks>\n        /// <exception cref=\"ArgumentNullException\">The childText parameter is\n        /// null.</exception>\n        void IAddChild.AddText(string childText)\n        {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/PointAnimationUsingKeyFrames.cs#L209-L245","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (XAML)\n<PointAnimationUsingKeyFrames>\n  <LinearDoubleKeyFrame Value=\"10\" KeyTime=\"0:0:1\" />\n</PointAnimationUsingKeyFrames>\n// after\n<PointAnimationUsingKeyFrames>\n  <LinearPointKeyFrame Value=\"10,10\" KeyTime=\"0:0:1\" />\n</PointAnimationUsingKeyFrames>","handlingStrategy":"validation","validationCode":"if (child is PointKeyFrame kf) pointAnimationUsingKeyFrames.KeyFrames.Add(kf); else throw new ArgumentException($\"Child must be a PointKeyFrame, got {child?.GetType().Name}\");","typeGuard":"static bool IsPointKeyFrame(object o) => o is PointKeyFrame;","tryCatchPattern":"try { xamlReader.Load(xaml); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"key frame\") || ex.Message.Contains(\"KeyFrame\")) { /* fix child element type in XAML */ }","preventionTips":["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"],"tags":["wpf","xaml","animation","keyframes"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}