dotnet/wpf · error · ArgumentException
SR.Timing_InvalidArgAccelAndDecel
Error message
SR.Timing_InvalidArgAccelAndDecel
What it means
Timeline.AccelerationRatio and Timeline.DecelerationRatio validate their value through ValidateAccelerationDecelerationRatio, which requires a double in [0, 1] that is not NaN. Values outside that range throw ArgumentException with Timing_InvalidArgAccelAndDecel.
Solutions
- Clamp before assigning: Math.Max(0, Math.Min(1, value)).
- Default NaN to 0 before assigning.
- In XAML/data binding, restrict the source value to [0,1] (slider Maximum=1) or add a conversion step.
Example fix
// before timeline.AccelerationRatio = userPercent; // e.g. 50 // after timeline.AccelerationRatio = Math.Clamp(userPercent / 100.0, 0.0, 1.0);
Defensive patterns
Strategy: validation
Validate before calling
double v = double.IsNaN(ratio) ? 0 : Math.Clamp(ratio, 0.0, 1.0); timeline.AccelerationRatio = v;
Type guard
static bool IsValidAccelDecelRatio(double v) => !double.IsNaN(v) && v >= 0 && v <= 1; static double SafeRatio(double v) => double.IsNaN(v) ? 0 : Math.Clamp(v, 0.0, 1.0);
Try / catch
try { timeline.AccelerationRatio = ratio; }
catch (ArgumentException) { timeline.AccelerationRatio = 0; } Prevention
- Store ratios as fractions (0..1), not percentages (0..100).
- Clamp slider-driven or user-entered values before assignment.
- Handle NaN from divisions feeding the ratio.
When it happens
Trigger: timeline.AccelerationRatio = 1.5, = -0.1, or = double.NaN. Also triggered by data binding to a computed property that returns a value outside 0..1.
Common situations: Computing the ratio as a percentage (e.g., 50 instead of 0.5); dividing by zero producing NaN; user input from a slider allowing values > 1; config values stored as percents.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- SR.Timing_InvalidArgFinitePositive
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
- SR.Animation_ChildMustBeKeyFrame
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d61e43804731f8f8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Timeline.cs:212
public double AccelerationRatio
{
get
{
return (double)GetValue(AccelerationRatioProperty);
}
set
{
SetValue(AccelerationRatioProperty, value);
}
}
private static bool ValidateAccelerationDecelerationRatio(object value)
{
double newValue = (double)value;
if (newValue < 0 || newValue > 1 || double.IsNaN(newValue))
{
throw new ArgumentException(SR.Timing_InvalidArgAccelAndDecel, nameof(value));
}
return true;
}
#endregion // AccelerationRatio Property
#region AutoReverse Property
/// <summary>
/// AutoReverseProperty
/// </summary>
public static readonly DependencyProperty AutoReverseProperty =
DependencyProperty.Register(
"AutoReverse",
typeof(bool),
typeof(Timeline),View on GitHub (pinned to 81131a70a4)