dotnet/wpf · error · ArgumentException
SR.Timing_InvalidArgFinitePositive
Error message
SR.Timing_InvalidArgFinitePositive
What it means
Timeline.SpeedRatio is validated by ValidateSpeedRatio, which requires a finite positive double: > 0, <= double.MaxValue, and not NaN. Zero, negative, NaN, or +Infinity values throw ArgumentException with Timing_InvalidArgFinitePositive.
Solutions
- Validate/guard before assignment: double.IsFinite(v) && v > 0 (note Infinity must be excluded).
- Clamp small/invalid values to a minimum like 0.001 or fall back to 1.
- For dynamic speed control, coerce the bound value in a value converter or property setter.
Example fix
// before timeline.SpeedRatio = newSpeed; // may be 0 or NaN // after timeline.SpeedRatio = double.IsFinite(newSpeed) && newSpeed > 0 ? newSpeed : 1.0;
Defensive patterns
Strategy: validation
Validate before calling
double v = double.IsFinite(speed) && speed > 0 ? speed : 1.0; timeline.SpeedRatio = v;
Type guard
static bool IsValidSpeedRatio(double v) => double.IsFinite(v) && v > 0; static double SafeSpeedRatio(double v) => double.IsFinite(v) && v > 0 ? v : 1.0;
Try / catch
try { timeline.SpeedRatio = speed; }
catch (ArgumentException) { timeline.SpeedRatio = 1.0; } Prevention
- Exclude 0, negatives, NaN, and Infinity before assignment.
- Guard divisions that compute speed (time divisor can be 0).
- Coerce numeric UI input to a safe minimum like 0.01.
When it happens
Trigger: timeline.SpeedRatio = 0, = -2, = double.NaN, or = double.PositiveInfinity (Infinity exceeds double.MaxValue per this check). Also via data binding to a value that can be 0.
Common situations: Computing speed from a divisor that yields 0 or Infinity (speed = distance/time with time 0); NaN from double.TryParse of empty input; UI numeric fields allowing 0 or negatives.
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.Timing_InvalidArgAccelAndDecel
- 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/9a9442d921f5fbd3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Timeline.cs:601
public double SpeedRatio
{
get
{
return (double)GetValue(SpeedRatioProperty);
}
set
{
SetValue(SpeedRatioProperty, value);
}
}
private static bool ValidateSpeedRatio(object value)
{
double newValue = (double)value;
if (newValue <= 0 || newValue > double.MaxValue || double.IsNaN(newValue))
{
throw new ArgumentException(SR.Timing_InvalidArgFinitePositive, nameof(value));
}
return true;
}
#endregion // SpeedRatio Property
#endregion // Properties
#region Methods
/// <summary>
/// Called by the <see ref="Clock.FromTimeline" /> method to
/// create a type-specific clock for this Timeline.
/// </summary>
/// <returns>
/// A clock for this Timeline.
/// </returns>View on GitHub (pinned to 81131a70a4)