dotnet/wpf · error · ArgumentException
SR.Animation_KeySpline_InvalidValue (ControlPoint2)
Error message
SR.Animation_KeySpline_InvalidValue (ControlPoint2)
What it means
The KeySpline.ControlPoint2 property setter throws ArgumentException (SR.Animation_KeySpline_InvalidValue) when the assigned point has any X or Y coordinate outside [0,1]. Like ControlPoint1, the value is only written after IsValidControlPoint passes, keeping the timing curve inside the unit square.
Solutions
- Clamp both coordinates into [0,1] before setting ControlPoint2.
- Validate in the input layer (slider ranges, numeric updown min/max) so out-of-range values never reach the setter.
- Catch ArgumentException around the assignment and revert to the previous value.
- Recreate the KeySpline via the constructor with both points validated together.
Example fix
// before spline.ControlPoint2 = parsedPoint; // after spline.ControlPoint2 = new Point(Math.Clamp(parsedPoint.X, 0, 1), Math.Clamp(parsedPoint.Y, 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.ControlPoint2 = value; Type guard
static Point SafeControlPoint2(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.ControlPoint2;
try { spline.ControlPoint2 = candidate; }
catch (ArgumentException) { spline.ControlPoint2 = previous; } Prevention
- Apply the same [0,1] clamp helper to both control points
- Check imported cubic-bezier data: some formats allow x outside [0,1]
- Constrain UI numeric inputs before they reach the setter
- Prefer recreating the KeySpline with validated points over in-place mutation
When it happens
Trigger: keySpline.ControlPoint2 = new Point(x, y) with x or y < 0.0 or > 1.0, e.g. from an easing editor or generated animation code.
Common situations: Easing-curve editors without input clamping; importing spline data from formats allowing overshoot (e.g. raw CSS cubic-bezier x-values outside [0,1]); percentage-based configuration.
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 (ControlPoint1)
- 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/7380f1461468bc96.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/KeySpline.cs:199
///
/// </summary>
public Point ControlPoint2
{
get
{
ReadPreamble();
return _controlPoint2;
}
set
{
WritePreamble();
if (value != _controlPoint2)
{
if (!IsValidControlPoint(value))
{
throw new ArgumentException(SR.Format(
SR.Animation_KeySpline_InvalidValue,
"ControlPoint2",
value));
}
_controlPoint2 = value;
WritePostscript();
}
}
}
/// <summary>
/// Calculates spline progress from a linear progress.
/// </summary>
/// <param name="linearProgress">the linear progress</param>
/// <returns>the spline progress</returns>
public double GetSplineProgress(double linearProgress)View on GitHub (pinned to 81131a70a4)