{"record":{"id":"dfb36f359744a891","repo":"AvaloniaUI/Avalonia","slug":"animation-target-can-t-be-null","errorCode":null,"errorMessage":"Animation Target can't be null","messagePattern":"Animation Target can't be null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Rendering/Composition/CompositionObject.cs","lineNumber":90,"sourceCode":"            if (propertyName is null)\n                throw new ArgumentNullException(nameof(propertyName));\n            if (Server is not ServerObject srv)\n                return;\n            var prop = srv.GetCompositionProperty(propertyName) ?? throw new ArgumentException(\"Unknown property \" + propertyName);\n            srv.Animations?.RemoveAnimationForProperty(prop);\n        }\n\n        /// <summary>\n        /// Starts an animation group.\n        /// The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup.\n        /// All the animations in the group will be started at the same time on the object.\n        /// </summary>\n        public void StartAnimationGroup(ICompositionAnimationBase grp)\n        {\n            if (grp is CompositionAnimation animation)\n            {\n                if(animation.Target == null)\n                    throw new ArgumentException(\"Animation Target can't be null\");\n                StartAnimation(animation.Target, animation);\n            }\n            else if (grp is CompositionAnimationGroup group)\n            {\n                foreach (var a in group.Animations)\n                {\n                    if (a.Target == null)\n                        throw new ArgumentException(\"Animation Target can't be null\");\n                    StartAnimation(a.Target, a);\n                }\n            }\n        }\n\n        bool StartAnimationGroupPart(CompositionAnimation animation, string target, ExpressionVariant finalValue)\n        {\n            if(animation.Target == null)\n                throw new ArgumentException(\"Animation Target can't be null\");\n            if (animation.Target == target)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Rendering/Composition/CompositionObject.cs#L72-L108","documentation":"StartAnimationGroup requires every animation's Target to be non-null before dispatching. The single-animation branch (grp is CompositionAnimation) checks animation.Target first and throws ArgumentException when it is null. Target is the property name the animation drives and must be set explicitly on CompositionAnimation.","triggerScenarios":"Calling StartAnimationGroup(singleAnimation) on an animation whose .Target was never assigned (it defaults to null).","commonSituations":"Creating a Scalar/Vector key-frame animation, configuring key frames, and forgetting anim.Target = \"...\" before grouping it; or passing a freshly created animation straight into StartAnimationGroup.","solutions":["Set animation.Target = \"Opacity\" (or the relevant animatable property) before StartAnimationGroup.","Prefer StartAnimation(propertyName, animation) which supplies the target explicitly and never needs .Target.","Add an assertion/guard that Target is non-null before grouping."],"exampleFix":"// before\nvar anim = compositor.CreateScalarKeyFrameAnimation();\nanim.InsertKeyFrame(1f, 0f);\nvisual.StartAnimationGroup(anim); // Target null -> throws\n\n// after\nanim.Target = \"Opacity\";\nvisual.StartAnimationGroup(anim);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(anim.Target))\n    anim.Target = \"Opacity\";\nvisual.StartAnimationGroup(anim);","typeGuard":"static bool HasTarget(CompositionAnimation a) => !string.IsNullOrEmpty(a.Target);","tryCatchPattern":null,"preventionTips":["Set animation.Target before StartAnimationGroup.","Prefer StartAnimation(propertyName, anim) which supplies the target explicitly.","Assert Target != null in debug builds before grouping."],"tags":["composition","animation","animation-group","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}