{"record":{"id":"02dc882557d19678","repo":"AvaloniaUI/Avalonia","slug":"delay-value-cannot-be-negative","errorCode":null,"errorMessage":"Delay value cannot be negative.","messagePattern":"Delay value cannot be negative\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/AnimationInstance`1.cs","lineNumber":93,"sourceCode":"            _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;\n            }\n            else\n            {\n                _iterationCount = null;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/AnimationInstance`1.cs#L75-L111","documentation":"Thrown by AnimationInstance.FetchProperties when Animation.Delay is negative. Delay represents the time before an animation's first iteration starts; a negative delay has no defined meaning in the timing model and is rejected during the per-sync property fetch.","triggerScenarios":"Setting Animation.Delay to a negative TimeSpan (e.g. via XAML Delay=\"-0:0:1\" or binding Delay to a computed negative duration). FetchProperties reads _animation.Delay and throws when it is less than TimeSpan.Zero.","commonSituations":"Binding Delay to a computed value that can go negative; XAML typos with a leading minus; theme resources that resolve to negative timespans; arithmetic on delays (e.g. delay = startOffset - elapsed) without clamping.","solutions":["Clamp Delay to TimeSpan.Zero (or a positive value) before assignment: anim.Delay = TimeSpan.FromMax(TimeSpan.Zero, value).","Validate the bound source so Delay cannot be negative (slider/resource minimums).","If you need 'start immediately', use Delay = TimeSpan.Zero rather than a negative value.","Audit XAML for stray negative Delay literals."],"exampleFix":"// before\n<Animation Delay=\"-0:0:0.5\" Duration=\"0:0:1\"/>\n\n// after\n<Animation Delay=\"0:0:0\" Duration=\"0:0:1\"/>","handlingStrategy":"validation","validationCode":"// clamp Delay to a non-negative value\nanimation.Delay = computedDelay < TimeSpan.Zero ? TimeSpan.Zero : computedDelay;","typeGuard":"static bool IsValidDelay(TimeSpan v) => v >= TimeSpan.Zero;","tryCatchPattern":null,"preventionTips":["Clamp Delay to TimeSpan.Zero or above before assigning.","Constrain bound sources so Delay cannot be negative.","Use Delay = TimeSpan.Zero for 'start immediately'.","Audit XAML for stray negative Delay literals."],"tags":["animation","delay","validation","timing"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}