{"record":{"id":"1bf93c3c9b221c69","repo":"dotnet/wpf","slug":"sr-animation-childmustbekeyframe-1bf93c","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/ObjectAnimationUsingKeyFrames.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            ObjectKeyFrame keyFrame = child as ObjectKeyFrame;\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/ObjectAnimationUsingKeyFrames.cs#L209-L245","documentation":"ObjectAnimationUsingKeyFrames.AddChild throws ArgumentException when the child object is not an ObjectKeyFrame. Key-frame animations only accept key frames as XAML children; any other child type is rejected.","triggerScenarios":"Calling AddChild(child) with a null or non-ObjectKeyFrame object, or XAML placing an unsupported element inside <ObjectAnimationUsingKeyFrames>.","commonSituations":"XAML mistakes like nesting a plain object, wrong key-frame type (e.g. a DoubleKeyFrame), or a typo'd element inside the animation.","solutions":["Wrap the child in a key frame, e.g. <DiscreteObjectKeyFrame Value=\"...\" KeyTime=\"...\">","Ensure the child derives from ObjectKeyFrame before calling AddChild","Use KeyFrames.Add directly in code with a correctly typed frame"],"exampleFix":"// before\n<objectAnimationUsingKeyFrames><sys:String>Foo</sys:String></objectAnimationUsingKeyFrames>\n// after\n<objectAnimationUsingKeyFrames><DiscreteObjectKeyFrame KeyTime=\"0:0:1\" Value=\"{x:Static sys:String.Empty}\"/></objectAnimationUsingKeyFrames>","handlingStrategy":"validation","validationCode":"if (child is ObjectKeyFrame kf) animation.AddChild(kf); else throw new ArgumentException(\"child must be an ObjectKeyFrame\");","typeGuard":"bool IsKeyFrameChild(object c) => c is ObjectKeyFrame;","tryCatchPattern":"try { animation.AddChild(child); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(child)) { /* wrap child in a DiscreteObjectKeyFrame instead */ }","preventionTips":["In XAML, only nest key frame elements inside key-frame animations","Wrap raw values in DiscreteObjectKeyFrame/other key frames","Match the key frame type to the animation type"],"tags":["wpf","animation","xaml","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"}