dotnet/wpf · error · ArgumentException

Timing_InvalidArgFinitePositive

Timing_InvalidArgFinitePositive

Error message

SR.Timing_InvalidArgFinitePositive (Timing_InvalidArgFinitePositive)

What it means

ClockController.SpeedRatio must be a finite positive double. The setter throws ArgumentException (Timing_InvalidArgFinitePositive) when the value is negative, NaN, or greater than double.MaxValue (i.e. not a valid finite positive number).

Solutions

  1. Validate before assigning: value > 0 && !double.IsNaN(value) && value < double.MaxValue
  2. Clamp computed ratios to a sane range (e.g. 0.1–10)
  3. Use double.IsFinite(value) checks on division-derived speeds
  4. Guard against division by zero when computing ratio from measured durations

Example fix

// before
double ratio = elapsed / measured; // can be NaN/Infinity
controller.SpeedRatio = ratio; // throws
// after
double ratio = measured > 0 ? elapsed / measured : 1.0;
if (ratio > 0 && !double.IsNaN(ratio) && ratio < double.MaxValue)
    controller.SpeedRatio = ratio;
Defensive patterns

Strategy: validation

Validate before calling

bool isValidSpeed(double v) => v > 0 && !double.IsNaN(v) && v < double.MaxValue;
if (isValidSpeed(candidate)) controller.SpeedRatio = candidate;

Type guard

static bool IsFinitePositive(double v) => !double.IsNaN(v) && !double.IsInfinity(v) && v > 0 && v < double.MaxValue;

Try / catch

try { controller.SpeedRatio = value; }
catch (ArgumentException) { controller.SpeedRatio = 1.0; }

Prevention

When it happens

Trigger: Setting controller.SpeedRatio = -1, double.NaN, double.PositiveInfinity, or double.MaxValue-boundary values; computing a speed ratio via division that yields NaN/Infinity (e.g. elapsed/0).

Common situations: Dynamic playback-speed controls fed by division expressions; data-bound SpeedRatio where the bound source contains NaN/Infinity; reverting speed after a pause with an uninitialized variable.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/47b605775e0ff8f7. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/ClockController.cs:279

            {
                return _owner;
            }
        }

        /// <summary>
        /// Returns or sets the interactive speed for the Clock.
        /// </summary>
        public double SpeedRatio
        {
            get
            {
                return _owner.InternalGetSpeedRatio();
            }
            set
            {
                if (value < 0 || value > double.MaxValue || double.IsNaN(value))
                {
                    throw new ArgumentException(SR.Timing_InvalidArgFinitePositive, nameof(value));
                }

                _owner.InternalSetSpeedRatio(value);
            }
        }

        #endregion // Properties
    }
}

View on GitHub (pinned to 81131a70a4)