{"record":{"id":"85f295eb0e813920","repo":"dotnet/wpf","slug":"sr-animation-notextchildren-animationusingkeyframestemplate","errorCode":null,"errorMessage":"SR.Animation_NoTextChildren","messagePattern":"SR\\.Animation_NoTextChildren","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationUsingKeyFramesTemplate.cs","lineNumber":355,"sourceCode":"                                    /// WritePreamble() or WritePostscript().  It also doesn't throw an\n                                    /// ArgumentNullException if the childText parameter is null.  These tasks\n                                    /// are performed by the interface implementation.  Therefore, it's OK\n                                    /// for a derived class to override this method and call the base\n                                    /// class implementation only if they determine that it's the right\n                                    /// course of action.  The derived class can rely on KeyFrameAnimation's\n                                    /// implementation of IAddChild.AddChild or implement their own\n                                    /// following the Freezable pattern since that would be a public\n                                    /// method.\n                                    /// </remarks>\n                                    /// <param name=\"childText\">A string representing the child text that\n                                    /// should be added.  If this is a KeyFrameAnimation an exception will be\n                                    /// thrown.</param>\n                                    /// <exception cref=\"InvalidOperationException\">Timelines have no way\n                                    /// of adding text.</exception>\n                                    [EditorBrowsable(EditorBrowsableState.Advanced)]\n                                    protected virtual void AddText(string childText)\n                                    {\n                                        throw new InvalidOperationException(SR.Animation_NoTextChildren);\n                                    }\n                                    \n                                    #endregion\n                                    \n                                    #region [[instance.TypeName]]AnimationBase\n                                    \n                                    /// <summary>\n                                    /// Calculates the value this animation believes should be the current value for the property.\n                                    /// </summary>\n                                    /// <param name=\"defaultOriginValue\">\n                                    /// This value is the suggested origin value provided to the animation\n                                    /// to be used if the animation does not have its own concept of a\n                                    /// start value. If this animation is the first in a composition chain\n                                    /// this value will be the snapshot value if one is available or the\n                                    /// base property value if it is not; otherise this value will be the \n                                    /// value returned by the previous animation in the chain with an \n                                    /// animationClock that is not Stopped.\n                                    /// </param>","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationUsingKeyFramesTemplate.cs#L337-L373","documentation":"WPF timeline/key-frame animation objects do not accept text content. AddText is the Advanced (code-generated) content-addition hook; because Timelines have no textual content model, any call throws InvalidOperationException with SR.Animation_NoTextChildren. The library throws it to signal a programmatic misuse of the content-building API surface rather than a data problem.","triggerScenarios":"Calling the protected AddText(string) method on a generated animation class (e.g. a DoubleAnimationUsingKeyFrames subclass built from the codegen Elements template), typically via XAML/object-model infrastructure that routes text children into AddChild/AddText.","commonSituations":"XAML compiler or markup writer emitting text into an animation element (e.g. <DoubleAnimationUsingKeyFrames>some text</...>); custom serialization code that treats animations like text-content controls; tooling that copies children between content models.","solutions":["Remove the text child from the animation element; animations accept only key frames/timelines as children","If you meant to configure the animation, set properties (e.g. Duration, KeyFrames) instead of supplying text","In custom code, never invoke AddText on Timeline-derived objects; call AddChild with a Timeline child"],"exampleFix":"// before\nnew DoubleAnimationUsingKeyFrames(); anim.AddText(\"0;1;2\");\n// after\nvar anim = new DoubleAnimationUsingKeyFrames();\nanim.KeyFrames.Add(new LinearDoubleKeyFrame(0));\nanim.KeyFrames.Add(new LinearDoubleKeyFrame(1));","handlingStrategy":"validation","validationCode":"if (anim is Timeline) throw new ArgumentException(\"Animations do not accept text children; supply Timeline children instead.\");","typeGuard":"bool IsTimeline(object o) => o is System.Windows.Media.Animation.Timeline;","tryCatchPattern":null,"preventionTips":["Never route text content into Timeline-derived elements","Use AddChild with Timeline instances only","Validate XAML content models for animation elements before runtime"],"tags":["wpf","animation","invalid-operation","xaml"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}