AvaloniaUI/Avalonia · error · ArgumentException
Invalid variant type: {typeof(T)}
Error message
Invalid variant type: {typeof(T)} What it means
Error "Invalid variant type: {typeof(T)}" thrown in AvaloniaUI/Avalonia.
Source
Thrown at src/Avalonia.Base/Rendering/Composition/Expressions/ExpressionVariant.cs:848
=> default(T) switch
{
bool => (bool)(object)v,
float => (float)(object)v,
double => (double)(object)v,
System.Numerics.Vector2 => (Vector2)(object)v,
Avalonia.Vector => (Vector)(object)v,
System.Numerics.Vector3 => (Vector3)(object)v,
Avalonia.Vector3D => (Vector3D)(object)v,
System.Numerics.Vector4 => (Vector4)(object)v,
System.Numerics.Matrix3x2 => (Matrix3x2)(object)v,
Avalonia.Matrix => (Matrix)(object)v,
System.Numerics.Matrix4x4 => (Matrix4x4)(object)v,
System.Numerics.Quaternion => (Quaternion)(object)v,
Avalonia.Media.Color => (Avalonia.Media.Color)(object)v,
Avalonia.RelativePoint => (RelativePoint)(object)v,
Avalonia.RelativeScalar => (RelativeScalar)(object)v,
Avalonia.RelativeUnit => (RelativeUnit)(object)v,
_ => throw new ArgumentException("Invalid variant type: " + typeof(T))
};
public T CastOrDefault<T>() where T : struct
{
TryCast<T>(out var r);
return r;
}
public override string ToString()
{
return Type switch
{
VariantType.Boolean => Boolean.ToString(),
VariantType.Double => Double.ToString(CultureInfo.InvariantCulture),
VariantType.Vector2 => Vector2.ToString(),
VariantType.Vector => Vector.ToString(),
VariantType.Vector3 => Vector3.ToString(),
VariantType.Vector3D => Vector3D.ToString(),View on GitHub (pinned to 11c5427268)
Solutions
- Use a supported ExpressionVariant type (e.g. float, Vector2, Vector3, Vector4, Color, bool, string) for the expression value.
- Convert the value to a supported scalar or vector type before assigning it to the variant.
When it happens
Trigger: Raised when code attempts to read or set an ExpressionVariant with a type that has no defined variant representation. Defend by only using supported variant types (scalars, vectors, matrices, strings, booleans, colors) in expression values.
Common situations: See trigger scenarios.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/93408f2c7964c138.
Report an issue: GitHub.