dotnet/wpf · error · ArgumentOutOfRangeException

ArgumentOutOfRangeException(nameof(value))

Error message

ArgumentOutOfRangeException(nameof(value))

What it means

InertiaTranslationBehavior.DesiredDeceleration setter throws ArgumentOutOfRangeException because the value must be a finite number; Infinity and NaN are rejected. Deceleration drives the physics simulation and infinite/NaN values would make the inertia animation non-deterministic. The library validates eagerly at set time rather than failing later during layout or animation.

Solutions

  1. Guard the computed value with double.IsFinite(value) before assigning; fall back to a sane default like 10.0 when not finite.
  2. Check the velocity/distance source values from ManipulationInertiaStartingEventArgs for zero or NaN before dividing.
  3. Catch ArgumentOutOfRangeException around the setter as a last-resort diagnostic.

Example fix

// before
behavior.DesiredDeceleration = distance / velocity; // may be NaN/Infinity
// after
double d = distance / velocity;
behavior.DesiredDeceleration = double.IsFinite(d) ? d : 10.0;
Defensive patterns

Strategy: validation

Validate before calling

if (!double.IsFinite(deceleration)) deceleration = 10.0;
behavior.DesiredDeceleration = deceleration;

Type guard

static bool IsValidDeceleration(double v) => double.IsFinite(v) && v > 0;

Try / catch

try { behavior.DesiredDeceleration = v; }
catch (ArgumentOutOfRangeException) { behavior.DesiredDeceleration = 10.0; }

Prevention

When it happens

Trigger: Assigning double.PositiveInfinity, double.NegativeInfinity, or double.NaN to InertiaTranslationBehavior.DesiredDeceleration, typically via manipulation inertia arguments or a computed value.

Common situations: Computing deceleration from a division that produced NaN/Infinity (e.g. dividing by a zero-measured velocity or distance), or initializing with an unset sentinel value before feeding real touch data.

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/64fac493b0de3bae. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaTranslationBehavior.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;
                _isDesiredDisplacementSet = false;
                _desiredDisplacement = double.NaN;
            }
        }

        /// <summary>
        ///     The desired total change in position.
        /// </summary>
        public double DesiredDisplacement
        {
            get { return _desiredDisplacement; }
            set
            {
                if (Double.IsInfinity(value) || Double.IsNaN(value))

View on GitHub (pinned to 81131a70a4)