{"record":{"id":"896883b085dcfb81","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-nameof-value-896883","errorCode":null,"errorMessage":"ArgumentOutOfRangeException(nameof(value))","messagePattern":"ArgumentOutOfRangeException\\(nameof\\(value\\)\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs","lineNumber":54,"sourceCode":"            get { return _initialVelocity; }\n            set\n            {\n                _isInitialVelocitySet = true;\n                _initialVelocity = value;\n            }\n        }\n\n        /// <summary>\n        ///     The desired rate of change of velocity in degrees/ms^2.\n        /// </summary>\n        public double DesiredDeceleration\n        {\n            get { return _desiredDeceleration; }\n            set\n            {\n                if (Double.IsInfinity(value) || Double.IsNaN(value))\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value));\n                }\n\n                _isDesiredDecelerationSet = true;\n                _desiredDeceleration = value;\n                _isDesiredRotationSet = false;\n                _desiredRotation = double.NaN;\n            }\n        }\n\n        /// <summary>\n        ///     The desired total change in angle in degrees.\n        /// </summary>\n        public double DesiredRotation\n        {\n            get { return _desiredRotation; }\n            set\n            {\n                if (Double.IsInfinity(value) || Double.IsNaN(value))","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaRotationBehavior.cs#L36-L72","documentation":"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.","triggerScenarios":"Assigning double.PositiveInfinity, double.NegativeInfinity, or double.NaN to inertiaRotationBehavior.DesiredDeceleration.","commonSituations":"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.","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."],"exampleFix":"// before\nbehavior.DesiredDeceleration = rotationRate; // rotationRate = double.NaN when not measured\n// after\nbehavior.DesiredDeceleration = double.IsFinite(rotationRate) ? rotationRate : 0.0001;","handlingStrategy":"validation","validationCode":"if (double.IsNaN(value) || double.IsInfinity(value)) value = 0.0001;\nbehavior.DesiredDeceleration = value;","typeGuard":"static bool IsUsableDeceleration(double v) => !double.IsNaN(v) && !double.IsInfinity(v);","tryCatchPattern":"try { behavior.DesiredDeceleration = rotationRate; }\ncatch (ArgumentOutOfRangeException)\n{ behavior.DesiredDeceleration = 0.0001; }","preventionTips":["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."],"tags":["wpf","touch","inertia","argument-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}