AvaloniaUI/Avalonia · error · ArgumentNullException
obj
Error message
obj
What it means
CompositionPropertySet.Set(key, CompositionObject) rejects a null CompositionObject with ArgumentNullException(nameof(obj)). This internal setter is the backing for CompositionAnimation.SetReferenceParameter, which forwards the compositionObject straight into the property set.
Source
Thrown at src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs:41
private readonly Dictionary<string, CompositionObject> _objects = new Dictionary<string, CompositionObject>();
internal CompositionPropertySet(Compositor compositor) : base(compositor, null)
{
}
internal void Set(string key, ExpressionVariant value)
{
_objects.Remove(key);
_variants[key] = value;
}
/*
For INTERNAL USE by CompositionAnimation ONLY, we DON'T support expression
paths like SomeParam.SomePropertyObject.SomeValue
*/
internal void Set(string key, CompositionObject obj)
{
_objects[key] = obj ?? throw new ArgumentNullException(nameof(obj));
_variants.Remove(key);
}
public void InsertColor(string propertyName, Avalonia.Media.Color value) => Set(propertyName, value);
public void InsertMatrix3x2(string propertyName, Matrix3x2 value) => Set(propertyName, value);
public void InsertMatrix4x4(string propertyName, Matrix4x4 value) => Set(propertyName, value);
public void InsertQuaternion(string propertyName, Quaternion value) => Set(propertyName, value);
public void InsertScalar(string propertyName, float value) => Set(propertyName, value);
public void InsertVector2(string propertyName, Vector2 value) => Set(propertyName, value);
public void InsertVector3(string propertyName, Vector3 value) => Set(propertyName, value);
public void InsertVector4(string propertyName, Vector4 value) => Set(propertyName, value);
View on GitHub (pinned to 11c5427268)
Solutions
- Never pass null to SetReferenceParameter; only register real composition objects.
- Null-check the object before registering it as a reference parameter.
- If a parameter is optional, omit the SetReferenceParameter call entirely instead of passing null.
Example fix
// before
anim.SetReferenceParameter("source", maybeNullVisual);
// after
if (maybeNullVisual != null)
anim.SetReferenceParameter("source", maybeNullVisual); Defensive patterns
Strategy: validation
Validate before calling
if (refObject is null) return;
anim.SetReferenceParameter("key", refObject); Type guard
static bool IsRegistrable(CompositionObject? o) => o is not null && !o.IsDisposed;
Prevention
- Null-check before SetReferenceParameter.
- For optional parameters, omit the call rather than passing null.
- Initialize referenced composition objects before registering them.
When it happens
Trigger: Calling CompositionAnimation.SetReferenceParameter("key", null), which internally calls _propertySet.Set(key, null).
Common situations: Passing an uninitialized CompositionObject field, or conditionally passing a reference parameter that evaluated to null, into an animation's reference parameters.
Related errors
- propertyName
- No Setter property assigned.
- Unknown PlaybackBehavior value: {_playbackBehavior}
- SpeedRatio value cannot be negative.
- Delay value cannot be negative.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/3815e1bbcda222d6.
Report an issue: GitHub.