dotnet/wpf · error · ArgumentOutOfRangeException
ArgumentOutOfRangeException(nameof(value))
Error message
ArgumentOutOfRangeException(nameof(value))
What it means
InertiaRotationBehavior.DesiredDeceleration throws ArgumentOutOfRangeException(nameof(value)) when the assigned value is Infinity or NaN. The setter enforces finite numeric deceleration so the inertia processor can produce a deterministic rotation animation.
Solutions
- Guard with double.IsFinite(value) before assignment.
- Fix the upstream computation that produced Infinity/NaN (check divisors and inputs).
- Omit the assignment to let WPF choose a default deceleration.
- Clamp non-finite values to a valid default before setting.
Example fix
// before behavior.DesiredDeceleration = rotationRate; // rotationRate = double.NaN when not measured // after behavior.DesiredDeceleration = double.IsFinite(rotationRate) ? rotationRate : 0.0001;
Defensive patterns
Strategy: validation
Validate before calling
if (double.IsNaN(value) || double.IsInfinity(value)) value = 0.0001; behavior.DesiredDeceleration = value;
Type guard
static bool IsUsableDeceleration(double v) => !double.IsNaN(v) && !double.IsInfinity(v);
Try / catch
try { behavior.DesiredDeceleration = rotationRate; }
catch (ArgumentOutOfRangeException)
{ behavior.DesiredDeceleration = 0.0001; } Prevention
- Guard rate calculations against division by zero (elapsed time).
- Validate user/config input for finiteness before assignment.
- Prefer not setting the property over passing NaN to mean 'default'.
- Add unit tests covering NaN/Infinity inputs for inertia property setters.
When it happens
Trigger: Assigning double.PositiveInfinity, double.NegativeInfinity, or double.NaN to inertiaRotationBehavior.DesiredDeceleration.
Common situations: Passing a rate computed from zero elapsed time (x/0 → Infinity); forwarding parsed config values without validation; using NaN as a sentinel that this setter rejects.
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
- ArgumentOutOfRangeException(nameof(value))
- ArgumentOutOfRangeException(nameof(value))
- args
- args
- ArgumentOutOfRangeException(authenticationType)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/896883b085dcfb81.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs:54
get { return _initialVelocity; }
set
{
_isInitialVelocitySet = true;
_initialVelocity = value;
}
}
/// <summary>
/// The desired rate of change of velocity in degrees/ms^2.
/// </summary>
public double DesiredDeceleration
{
get { return _desiredDeceleration; }
set
{
if (Double.IsInfinity(value) || Double.IsNaN(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
_isDesiredDecelerationSet = true;
_desiredDeceleration = value;
_isDesiredRotationSet = false;
_desiredRotation = double.NaN;
}
}
/// <summary>
/// The desired total change in angle in degrees.
/// </summary>
public double DesiredRotation
{
get { return _desiredRotation; }
set
{
if (Double.IsInfinity(value) || Double.IsNaN(value))View on GitHub (pinned to 81131a70a4)