{"record":{"id":"37782e48c8d5fbf6","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-nameof-value","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/InertiaExpansionBehavior.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.\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                _isDesiredExpansionSet = false;\n                _desiredExpansion = new Vector(double.NaN, double.NaN);\n            }\n        }\n\n        /// <summary>\n        ///     The desired total change in size.\n        /// </summary>\n        public Vector DesiredExpansion\n        {\n            get { return _desiredExpansion; }\n            set\n            {\n                _isDesiredExpansionSet = true;","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InertiaExpansionBehavior.cs#L36-L72","documentation":"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.","triggerScenarios":"Setting inertiaExpansionBehavior.DesiredDeceleration = double.PositiveInfinity/NaN (often from a computed value, config, or a division by zero producing Infinity/NaN).","commonSituations":"Computing deceleration as distance/0; parsing unvalidated user or configuration input; passing NaN as an 'unset' sentinel.","solutions":["Validate the value with double.IsFinite(value) before assigning.","Compute deceleration defensively: check the divisor is non-zero and the result is finite.","Use the default behavior (don't set DesiredDeceleration) or double.NaN internally by not setting _isDesiredDecelerationSet.","Clamp or substitute a sensible default (e.g. 0.001) when input is non-finite."],"exampleFix":"// before\nbehavior.DesiredDeceleration = totalDistance / elapsedTime; // may be Infinity\n// after\nvar decel = elapsedTime > 0 ? totalDistance / elapsedTime : 0.001;\nbehavior.DesiredDeceleration = double.IsFinite(decel) ? decel : 0.001;","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(value)) throw new ArgumentOutOfRangeException(nameof(value));\nbehavior.DesiredDeceleration = value;","typeGuard":"static bool IsFinite(double v) => !double.IsNaN(v) && !double.IsInfinity(v);","tryCatchPattern":"try { behavior.DesiredDeceleration = computedValue; }\ncatch (ArgumentOutOfRangeException)\n{ behavior.DesiredDeceleration = 0.001; }","preventionTips":["Validate any computed deceleration with double.IsFinite before assigning.","Check divisors are non-zero when deriving deceleration from distance/time.","Never use NaN/Infinity as an 'unset' sentinel for this property — simply don't set it.","Sanitize parsed configuration values before applying them to inertia behavior."],"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"}