dotnet/wpf · error · ArgumentException
SR.Animation_KeySpline_InvalidValue (ControlPoint1)
Error message
SR.Animation_KeySpline_InvalidValue (ControlPoint1)
What it means
The KeySpline.ControlPoint1 property setter throws ArgumentException (SR.Animation_KeySpline_InvalidValue) when assigning a point whose X or Y is outside the required [0,1] range. The setter only validates when the new value differs from the current one, but any genuinely out-of-range assignment fails.
Solutions
- Clamp the point before assignment: new Point(Math.Clamp(x,0,1), Math.Clamp(y,0,1)).
- Constrain UI inputs (sliders min=0 max=1) or normalize parsed values by dividing by their max.
- Wrap the setter in try/catch (ArgumentException) and keep/restore the previous control point.
- If the spline is replaceable, construct a new KeySpline with validated points instead of mutating.
Example fix
// before spline.ControlPoint1 = new Point(userX, userY); // after spline.ControlPoint1 = new Point(Math.Clamp(userX, 0, 1), Math.Clamp(userY, 0, 1));
Defensive patterns
Strategy: validation
Validate before calling
if (value.X < 0 || value.X > 1 || value.Y < 0 || value.Y > 1)
value = new Point(Math.Clamp(value.X, 0, 1), Math.Clamp(value.Y, 0, 1));
spline.ControlPoint1 = value; Type guard
static Point SafeControlPoint1(Point p) => new Point(Math.Clamp(p.X, 0.0, 1.0), Math.Clamp(p.Y, 0.0, 1.0));
Try / catch
Point previous = spline.ControlPoint1;
try { spline.ControlPoint1 = candidate; }
catch (ArgumentException) { spline.ControlPoint1 = previous; } Prevention
- Bind spline editors to sliders with Minimum=0, Maximum=1
- Clamp computed/animated control points before assignment
- Validate values parsed from XAML/config for range, not just type
- Never assign raw external easing data without normalization
When it happens
Trigger: keySpline.ControlPoint1 = new Point(x, y) where x < 0, x > 1, y < 0 or y > 1; also storyboard/key-frame code paths that assign control points computed at runtime.
Common situations: Animating spline control points driven by sliders or parsed input without range constraints; config systems storing 0-100 percent values; cumulative arithmetic drift pushing coordinates slightly above 1.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.Animation_KeySpline_InvalidValue (ControlPoint2)
- SR.Animation_KeySpline_InvalidValue
- SR.Animation_KeySpline_InvalidValue (controlPoint1)
- Animation_AnimationTimelineTypeMismatch
- Animation_CalculatedValueIsInvalidForProperty
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4ac18ffcd52ffe29.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs:167
///
/// </summary>
public Point ControlPoint1
{
get
{
ReadPreamble();
return _controlPoint1;
}
set
{
WritePreamble();
if (value != _controlPoint1)
{
if (!IsValidControlPoint(value))
{
throw new ArgumentException(SR.Format(
SR.Animation_KeySpline_InvalidValue,
"ControlPoint1",
value));
}
_controlPoint1 = value;
WritePostscript();
}
}
}
/// <summary>
///
/// </summary>
public Point ControlPoint2
{
getView on GitHub (pinned to 81131a70a4)