{"record":{"id":"50dbd356a278317e","repo":"dotnet/wpf","slug":"sr-animation-childmustbekeyframe-50dbd3","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/DecimalAnimationUsingKeyFrames.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            DecimalKeyFrame keyFrame = child as DecimalKeyFrame;\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/DecimalAnimationUsingKeyFrames.cs#L209-L245","documentation":"DecimalAnimationUsingKeyFrames.AddChild throws ArgumentException (SR.Animation_ChildMustBeKeyFrame) when the supplied child is not a DecimalKeyFrame. Key-frame animations only accept key frames as children; the parameter name 'child' accompanies the message.","triggerScenarios":"Calling AddChild with anything other than a DecimalKeyFrame — a raw decimal, string, or a key frame of the wrong element type.","commonSituations":"XAML mistakes nesting a wrong element inside <DecimalAnimationUsingKeyFrames>; generated code passing the numeric value directly instead of a key frame object.","solutions":["Pass only DecimalKeyFrame-derived objects (DiscreteDecimalKeyFrame, LinearDecimalKeyFrame, SplineDecimalKeyFrame)","Wrap the value in a key frame with a KeyTime","Correct the XAML child element type","Use KeyFrames.Add with the proper key frame type explicitly"],"exampleFix":"// before\nanimation.AddChild(5m); // ArgumentException\n// after\nanimation.AddChild(new LinearDecimalKeyFrame(5m, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))));","handlingStrategy":"type-guard","validationCode":"if (child is DecimalKeyFrame keyFrame)\n    animation.AddChild(keyFrame);\nelse\n    throw new ArgumentException($\"Child must be a DecimalKeyFrame, got {child?.GetType().Name}\");","typeGuard":"static bool IsDecimalKeyFrame(object child) => child is DecimalKeyFrame;","tryCatchPattern":"try { animation.AddChild(child); }\ncatch (ArgumentException ex) when (ex.ParamName == \"child\") { /* wrap value in a key frame instead */ }","preventionTips":["Only nest *DecimalKeyFrame elements in DecimalAnimationUsingKeyFrames","Wrap numeric values in Linear/Discrete/SplineDecimalKeyFrame","Use KeyFrames.Add(DecimalKeyFrame) for type safety"],"tags":["wpf","animation","keyframes","argument"],"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"}