{"record":{"id":"01774c9c02bd911f","repo":"AvaloniaUI/Avalonia","slug":"speedratio-value-cannot-be-negative","errorCode":null,"errorMessage":"SpeedRatio value cannot be negative.","messagePattern":"SpeedRatio value cannot be negative\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/AnimationInstance`1.cs","lineNumber":89,"sourceCode":"            _interpolator = Interpolator;\n            _baseClock = baseClock;\n            _initialKFValue = default!;\n            _neutralValue = default!;\n            _shouldPauseOnInvisible = shouldPauseOnInvisible;\n            _isFirstFrame = true;\n            _isInFirstInitialDelay = true;\n            _speedRatio = 1;\n            FetchProperties();\n        }\n\n        private void FetchProperties()\n        {\n            _easeFunc = _animation.Easing;\n\n            _speedRatioPrev = _speedRatio;\n            _speedRatio = _animation.SpeedRatio;\n            if (_speedRatio < 0d)\n                throw new InvalidOperationException(\"SpeedRatio value cannot be negative.\");\n\n            _initialDelay = _animation.Delay;\n            if (_initialDelay < TimeSpan.Zero)\n                throw new InvalidOperationException(\"Delay value cannot be negative.\");\n\n            _duration = _animation.Duration;\n            if (_duration < TimeSpan.Zero)\n                throw new InvalidOperationException(\"Duration value cannot be negative.\");\n\n            _iterationDelay = _animation.DelayBetweenIterations;\n            if (_iterationDelay < TimeSpan.Zero)\n                throw new InvalidOperationException(\"DelayBetweenIterations value cannot be negative.\");\n\n            if (_animation.IterationCount.RepeatType == IterationType.Many)\n            {\n                if (_animation.IterationCount.Value > long.MaxValue)\n                    throw new InvalidOperationException(\"IterationCount value cannot be larger than long.MaxValue.\");\n                _iterationCount = (long)_animation.IterationCount.Value;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/AnimationInstance`1.cs#L71-L107","documentation":"Thrown by AnimationInstance.FetchProperties when Animation.SpeedRatio is negative. SpeedRatio scales playback rate; a negative value would imply reverse playback at the rate level, which the timing engine does not support, so it is rejected during the property fetch that runs on each sync.","triggerScenarios":"Setting Animation.SpeedRatio to a value < 0 (e.g. via XAML SpeedRatio=\"-1\" or binding SpeedRatio to a computed negative number). FetchProperties reads _animation.SpeedRatio on each fetch and throws immediately when it is negative.","commonSituations":"Binding SpeedRatio to a data source that can go negative (e.g. a slider or velocity-derived value); typos in XAML with a leading minus; reusable styles/templates where a theme resource accidentally becomes negative; runtime computation errors producing negative ratios.","solutions":["Clamp SpeedRatio to >= 0 before assigning: anim.SpeedRatio = Math.Max(0, value).","If reverse playback is desired, use IterationCount / Direction semantics or reverse the keyframe order rather than a negative ratio.","Validate the bound source value (e.g. slider Minimum=0) so SpeedRatio cannot become negative.","Review XAML for stray negative literals on SpeedRatio."],"exampleFix":"// before\n<Animation SpeedRatio=\"-1\" Duration=\"0:0:1\"/>\n\n// after\n<Animation SpeedRatio=\"1\" Duration=\"0:0:1\"/>","handlingStrategy":"validation","validationCode":"// clamp SpeedRatio to a non-negative value\nanimation.SpeedRatio = Math.Max(0d, computedSpeedRatio);","typeGuard":"static bool IsValidSpeedRatio(double v) => v >= 0d;","tryCatchPattern":null,"preventionTips":["Clamp SpeedRatio to >= 0 before assigning.","Constrain bound sources (sliders, computed values) to non-negative ranges.","For reverse playback, use direction/keyframe ordering, not negative ratios.","Audit XAML for stray negative SpeedRatio literals."],"tags":["animation","speedratio","validation","timing"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}