dotnet/wpf · error · ArgumentOutOfRangeException

ArgumentOutOfRangeException(nameof(value))

Error message

ArgumentOutOfRangeException(nameof(value))

What it means

InertiaExpansionBehavior.DesiredDeceleration rejects Double.PositiveInfinity, Double.NegativeInfinity, and Double.NaN by throwing ArgumentOutOfRangeException(nameof(value)). Deceleration must be a finite real number (units of expansion per ms²) for the inertia processor to compute a valid animation.

Solutions

  1. Validate the value with double.IsFinite(value) before assigning.
  2. Compute deceleration defensively: check the divisor is non-zero and the result is finite.
  3. Use the default behavior (don't set DesiredDeceleration) or double.NaN internally by not setting _isDesiredDecelerationSet.
  4. Clamp or substitute a sensible default (e.g. 0.001) when input is non-finite.

Example fix

// before
behavior.DesiredDeceleration = totalDistance / elapsedTime; // may be Infinity
// after
var decel = elapsedTime > 0 ? totalDistance / elapsedTime : 0.001;
behavior.DesiredDeceleration = double.IsFinite(decel) ? decel : 0.001;
Defensive patterns

Strategy: validation

Validate before calling

if (!double.IsFinite(value)) throw new ArgumentOutOfRangeException(nameof(value));
behavior.DesiredDeceleration = value;

Type guard

static bool IsFinite(double v) => !double.IsNaN(v) && !double.IsInfinity(v);

Try / catch

try { behavior.DesiredDeceleration = computedValue; }
catch (ArgumentOutOfRangeException)
{ behavior.DesiredDeceleration = 0.001; }

Prevention

When it happens

Trigger: Setting inertiaExpansionBehavior.DesiredDeceleration = double.PositiveInfinity/NaN (often from a computed value, config, or a division by zero producing Infinity/NaN).

Common situations: Computing deceleration as distance/0; parsing unvalidated user or configuration input; passing NaN as an 'unset' sentinel.

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


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaExpansionBehavior.cs:54

            get { return _initialVelocity; }
            set
            {
                _isInitialVelocitySet = true;
                _initialVelocity = value;
            }
        }

        /// <summary>
        ///     The desired rate of change of velocity.
        /// </summary>
        public double DesiredDeceleration
        {
            get { return _desiredDeceleration; }
            set
            {
                if (Double.IsInfinity(value) || Double.IsNaN(value))
                {
                    throw new ArgumentOutOfRangeException(nameof(value));
                }

                _isDesiredDecelerationSet = true;
                _desiredDeceleration = value;
                _isDesiredExpansionSet = false;
                _desiredExpansion = new Vector(double.NaN, double.NaN);
            }
        }

        /// <summary>
        ///     The desired total change in size.
        /// </summary>
        public Vector DesiredExpansion
        {
            get { return _desiredExpansion; }
            set
            {
                _isDesiredExpansionSet = true;

View on GitHub (pinned to 81131a70a4)