{"record":{"id":"64fac493b0de3bae","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-nameof-value-64fac4","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/InertiaTranslationBehavior.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                _isDesiredDisplacementSet = false;\n                _desiredDisplacement = double.NaN;\n            }\n        }\n\n        /// <summary>\n        ///     The desired total change in position.\n        /// </summary>\n        public double DesiredDisplacement\n        {\n            get { return _desiredDisplacement; }\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/InertiaTranslationBehavior.cs#L36-L72","documentation":"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.","triggerScenarios":"Assigning double.PositiveInfinity, double.NegativeInfinity, or double.NaN to InertiaTranslationBehavior.DesiredDeceleration, typically via manipulation inertia arguments or a computed value.","commonSituations":"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.","solutions":["Guard the computed value with double.IsFinite(value) before assigning; fall back to a sane default like 10.0 when not finite.","Check the velocity/distance source values from ManipulationInertiaStartingEventArgs for zero or NaN before dividing.","Catch ArgumentOutOfRangeException around the setter as a last-resort diagnostic."],"exampleFix":"// before\nbehavior.DesiredDeceleration = distance / velocity; // may be NaN/Infinity\n// after\ndouble d = distance / velocity;\nbehavior.DesiredDeceleration = double.IsFinite(d) ? d : 10.0;","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(deceleration)) deceleration = 10.0;\nbehavior.DesiredDeceleration = deceleration;","typeGuard":"static bool IsValidDeceleration(double v) => double.IsFinite(v) && v > 0;","tryCatchPattern":"try { behavior.DesiredDeceleration = v; }\ncatch (ArgumentOutOfRangeException) { behavior.DesiredDeceleration = 10.0; }","preventionTips":["Always check double.IsFinite on values derived from division (velocity, distance).","Use a named default constant instead of NaN sentinels for unset inertia values.","Set inertia properties inside ManipulationInertiaStarting where real measured data is guaranteed."],"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-21T21:30:21.729Z"}