{"record":{"id":"d61e43804731f8f8","repo":"dotnet/wpf","slug":"sr-timing-invalidargaccelanddecel","errorCode":null,"errorMessage":"SR.Timing_InvalidArgAccelAndDecel","messagePattern":"SR\\.Timing_InvalidArgAccelAndDecel","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Timeline.cs","lineNumber":212,"sourceCode":"        public double AccelerationRatio\n        {\n            get\n            {\n                return (double)GetValue(AccelerationRatioProperty);\n            }\n            set\n            {\n                SetValue(AccelerationRatioProperty, value);\n            }\n        }\n\n        private static bool ValidateAccelerationDecelerationRatio(object value)\n        {\n            double newValue = (double)value;\n\n            if (newValue < 0 || newValue > 1 || double.IsNaN(newValue))\n            {\n                throw new ArgumentException(SR.Timing_InvalidArgAccelAndDecel, nameof(value));\n            }\n\n            return true;\n        }\n\n        #endregion // AccelerationRatio Property\n\n\n        #region AutoReverse Property\n\n        /// <summary>\n        /// AutoReverseProperty\n        /// </summary>\n        public static readonly DependencyProperty AutoReverseProperty =\n            DependencyProperty.Register(\n                \"AutoReverse\",\n                typeof(bool),\n                typeof(Timeline),","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Timeline.cs#L194-L230","documentation":"Timeline.AccelerationRatio and Timeline.DecelerationRatio validate their value through ValidateAccelerationDecelerationRatio, which requires a double in [0, 1] that is not NaN. Values outside that range throw ArgumentException with Timing_InvalidArgAccelAndDecel.","triggerScenarios":"timeline.AccelerationRatio = 1.5, = -0.1, or = double.NaN. Also triggered by data binding to a computed property that returns a value outside 0..1.","commonSituations":"Computing the ratio as a percentage (e.g., 50 instead of 0.5); dividing by zero producing NaN; user input from a slider allowing values > 1; config values stored as percents.","solutions":["Clamp before assigning: Math.Max(0, Math.Min(1, value)).","Default NaN to 0 before assigning.","In XAML/data binding, restrict the source value to [0,1] (slider Maximum=1) or add a conversion step."],"exampleFix":"// before\ntimeline.AccelerationRatio = userPercent; // e.g. 50\n// after\ntimeline.AccelerationRatio = Math.Clamp(userPercent / 100.0, 0.0, 1.0);","handlingStrategy":"validation","validationCode":"double v = double.IsNaN(ratio) ? 0 : Math.Clamp(ratio, 0.0, 1.0);\ntimeline.AccelerationRatio = v;","typeGuard":"static bool IsValidAccelDecelRatio(double v) => !double.IsNaN(v) && v >= 0 && v <= 1;\nstatic double SafeRatio(double v) => double.IsNaN(v) ? 0 : Math.Clamp(v, 0.0, 1.0);","tryCatchPattern":"try { timeline.AccelerationRatio = ratio; }\ncatch (ArgumentException) { timeline.AccelerationRatio = 0; }","preventionTips":["Store ratios as fractions (0..1), not percentages (0..100).","Clamp slider-driven or user-entered values before assignment.","Handle NaN from divisions feeding the ratio."],"tags":["wpf","animation","timeline","argument"],"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"}