AvaloniaUI/Avalonia · error · ArgumentException
Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.
Error message
Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.
What it means
Thrown by the ControlPointX1 setter when the supplied X1 value fails IsValidXValue, i.e. it is less than 0.0 or greater than 1.0. The constraint applies only to X coordinates because they represent normalized time on the bezier easing curve; Y coordinates (progress) are unconstrained.
Source
Thrown at src/Avalonia.Base/Animation/KeySpline.cs:105
return new KeySpline(tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble(), tokenizer.ReadDouble());
}
/// <summary>
/// X coordinate of the first control point
/// </summary>
public double ControlPointX1
{
get => _controlPointX1;
set
{
if (IsValidXValue(value))
{
_controlPointX1 = value;
_isDirty = true;
}
else
{
throw new ArgumentException("Invalid KeySpline X1 value. Must be >= 0.0 and <= 1.0.");
}
}
}
/// <summary>
/// Y coordinate of the first control point
/// </summary>
public double ControlPointY1
{
get => _controlPointY1;
set
{
_controlPointY1 = value;
_isDirty = true;
}
}
/// <summary>View on GitHub (pinned to 11c5427268)
Solutions
- Clamp the value to [0,1] before assigning: Math.Clamp(v, 0.0, 1.0).
- Use the constructor KeySpline(x1,y1,x2,y2) only after validating, or set Y coordinates freely and keep X in range.
- If the value comes from a string, validate with double.TryParse under InvariantCulture before assignment.
Example fix
// before spline.ControlPointX1 = 1.2; // after spline.ControlPointX1 = Math.Clamp(1.2, 0.0, 1.0);
Defensive patterns
Strategy: validation
Validate before calling
double x1 = Math.Clamp(rawX1, 0.0, 1.0); spline.ControlPointX1 = x1;
Type guard
static bool IsValidX(double v) => double.IsFinite(v) && v >= 0.0 && v <= 1.0;
Try / catch
try { spline.ControlPointX1 = v; }
catch (ArgumentException) { spline.ControlPointX1 = Math.Clamp(v, 0.0, 1.0); } Prevention
- Clamp user-provided X values before assignment.
- Parse strings under InvariantCulture and reject NaN/Infinity.
When it happens
Trigger: Assigning a number outside [0,1] to KeySpline.ControlPointX1 directly, or via reflection/serialization; parsing a malformed string into a KeySpline and then mutating X1.
Common situations: Treating the first control point like a free 2D point and setting X to values like 2.0 or -0.5; culture-related parse bugs producing NaN that then get assigned.
Related errors
- {nameof(KeySpline)} must have X coordinates >= 0.0 and <= 1.
- Invalid KeySpline X2 value. Must be >= 0.0 and <= 1.0.
- Transition elements have different parents.
- No Setter property assigned.
- Unknown PlaybackBehavior value: {_playbackBehavior}
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/4aaf89b41f64cc11.
Report an issue: GitHub.