{"record":{"id":"c58818c54dd7eb07","repo":"dotnet/wpf","slug":"animation-childmustbekeyframe-sr","errorCode":"Animation_ChildMustBeKeyFrame","errorMessage":"SR.Animation_ChildMustBeKeyFrame (Animation_ChildMustBeKeyFrame)","messagePattern":"SR\\.Animation_ChildMustBeKeyFrame \\(Animation_ChildMustBeKeyFrame\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ByteAnimationUsingKeyFrames.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            ByteKeyFrame keyFrame = child as ByteKeyFrame;\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/ByteAnimationUsingKeyFrames.cs#L209-L245","documentation":"ByteAnimationUsingKeyFrames.AddChild throws ArgumentException (SR.Animation_ChildMustBeKeyFrame, paramName \"child\") when a null or non-KeyFrame child is added via the IAddChild AddChild path. Key-frame animations only accept ByteKeyFrame children, so any other child object is rejected.","triggerScenarios":"Using XAML IAddChild syntax with a child element that is not a ByteKeyFrame (e.g. <ByteAnimationUsingKeyFrames><Byte>...</Byte></ByteAnimationUsingKeyFrames>), or calling AddChild(null) / AddChild(someNonKeyFrame).","commonSituations":"XAML authoring mistakes: nesting a plain value, DoubleAnimation, or wrong key-frame type inside a key-frame animation; key-frame type doesn't match the animated type.","solutions":["Add only ByteKeyFrame-derived children such as <DiscreteByteKeyFrame Value=\"10\" KeyTime=\"0:0:1\"/>","Use the KeyFrames collection property explicitly in code: animation.KeyFrames.Add(new LinearByteKeyFrame(...))","If a plain value was intended, use ByteAnimation instead of ByteAnimationUsingKeyFrames"],"exampleFix":"// before (XAML)\n<ByteAnimationUsingKeyFrames>\n  <Byte>10</Byte>\n</ByteAnimationUsingKeyFrames>\n// after\n<ByteAnimationUsingKeyFrames>\n  <DiscreteByteKeyFrame Value=\"10\" KeyTime=\"0:0:1\"/>\n</ByteAnimationUsingKeyFrames>","handlingStrategy":"validation","validationCode":"if (child is ByteKeyFrame kf) animation.KeyFrames.Add(kf);\nelse throw new ArgumentException(\"Child must be a ByteKeyFrame\", nameof(child));","typeGuard":"static bool IsKeyFrameChild(object o) => o is ByteKeyFrame;","tryCatchPattern":"try { adder.AddChild(child); }\ncatch (ArgumentException ex) when (ex.ParamName == \"child\") { /* child was not a key frame; fix XAML or wrap in a key frame */ }","preventionTips":["In XAML, nest only ByteKeyFrame-derived elements inside ByteAnimationUsingKeyFrames","Verify key-frame element type matches the animation's value type (byte)","In code, use the KeyFrames collection property instead of IAddChild"],"tags":["wpf","animation","xaml","keyframe","invalid-child"],"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"}