AvaloniaUI/Avalonia · error · ArgumentException
Animation Target can't be null
Error message
Animation Target can't be null
What it means
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.
Source
Thrown at src/Avalonia.Base/Rendering/Composition/CompositionObject.cs:90
if (propertyName is null)
throw new ArgumentNullException(nameof(propertyName));
if (Server is not ServerObject srv)
return;
var prop = srv.GetCompositionProperty(propertyName) ?? throw new ArgumentException("Unknown property " + propertyName);
srv.Animations?.RemoveAnimationForProperty(prop);
}
/// <summary>
/// Starts an animation group.
/// The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup.
/// All the animations in the group will be started at the same time on the object.
/// </summary>
public void StartAnimationGroup(ICompositionAnimationBase grp)
{
if (grp is CompositionAnimation animation)
{
if(animation.Target == null)
throw new ArgumentException("Animation Target can't be null");
StartAnimation(animation.Target, animation);
}
else if (grp is CompositionAnimationGroup group)
{
foreach (var a in group.Animations)
{
if (a.Target == null)
throw new ArgumentException("Animation Target can't be null");
StartAnimation(a.Target, a);
}
}
}
bool StartAnimationGroupPart(CompositionAnimation animation, string target, ExpressionVariant finalValue)
{
if(animation.Target == null)
throw new ArgumentException("Animation Target can't be null");
if (animation.Target == target)View on GitHub (pinned to 11c5427268)
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.
Example fix
// before var anim = compositor.CreateScalarKeyFrameAnimation(); anim.InsertKeyFrame(1f, 0f); visual.StartAnimationGroup(anim); // Target null -> throws // after anim.Target = "Opacity"; visual.StartAnimationGroup(anim);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(anim.Target))
anim.Target = "Opacity";
visual.StartAnimationGroup(anim); Type guard
static bool HasTarget(CompositionAnimation a) => !string.IsNullOrEmpty(a.Target);
Prevention
- Set animation.Target before StartAnimationGroup.
- Prefer StartAnimation(propertyName, anim) which supplies the target explicitly.
- Assert Target != null in debug builds before grouping.
When it happens
Trigger: Calling StartAnimationGroup(singleAnimation) on an animation whose .Target was never assigned (it defaults to null).
Common situations: 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.
Related errors
- Unknown property {propertyName}
- Transition elements have different parents.
- {nameof(KeySpline)} must have X coordinates >= 0.0 and <= 1.
- Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.
- Invalid KeySpline X2 value. Must be >= 0.0 and <= 1.0.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/dfb36f359744a891.
Report an issue: GitHub.