{"record":{"id":"63d3a4b374a4bf06","repo":"dotnet/wpf","slug":"sr-animation-childmustbekeyframe-63d3a4","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/Int32AnimationUsingKeyFrames.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            Int32KeyFrame keyFrame = child as Int32KeyFrame;\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/Int32AnimationUsingKeyFrames.cs#L209-L245","documentation":"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.","triggerScenarios":"Declaring a non-key-frame child element inside <Int32AnimationUsingKeyFrames> in XAML, or calling AddChild with an object that is not an Int32KeyFrame.","commonSituations":"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.","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."],"exampleFix":"// before\n<Int32AnimationUsingKeyFrames>\n  <Int32Animation ... />\n</Int32AnimationUsingKeyFrames>\n// after\n<Int32AnimationUsingKeyFrames>\n  <LinearInt32KeyFrame KeyTime=\"0:0:1\" Value=\"100\" />\n</Int32AnimationUsingKeyFrames>","handlingStrategy":"validation","validationCode":"if (child is not Int32KeyFrame)\n    throw new ArgumentException(\"Children of Int32AnimationUsingKeyFrames must be Int32KeyFrame instances\", nameof(child));","typeGuard":"bool IsInt32KeyFrame(object o) => o is Int32KeyFrame;","tryCatchPattern":"try { animation.AddChild(child); }\ncatch (ArgumentException ex) when (ex.ParamName == \"child\") {\n    // replace with the correct typed key frame\n}","preventionTips":["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"],"tags":["wpf","animation","xaml","type-mismatch"],"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"}