{"record":{"id":"9fcc6c4c613d2cdc","repo":"AvaloniaUI/Avalonia","slug":"iterationcount-value-cannot-be-larger-than-long-ma","errorCode":null,"errorMessage":"IterationCount value cannot be larger than long.MaxValue.","messagePattern":"IterationCount value cannot be larger than long\\.MaxValue\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/AnimationInstance`1.cs","lineNumber":106,"sourceCode":"            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;\n            }\n\n            _playbackDirectionPrev = _playbackDirection;\n            _playbackDirection = _animation.PlaybackDirection;\n            _fillMode = _animation.FillMode;\n        }\n\n        protected override void Unsubscribed()\n        {\n            // Guard against reentrancy: DoComplete() can trigger Unsubscribed() via the\n            // _onCompleteAction disposal chain, and then PublishCompleted() calls it again.\n            var timerSub = _timerSub;\n            _timerSub = null;","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/AnimationInstance`1.cs#L88-L124","documentation":"Thrown when IterationCount.RepeatType is IterationType.Many and IterationCount.Value (a ulong) exceeds long.MaxValue. AnimationInstance internally stores the count as a long?, so any value above long.MaxValue would overflow the cast and is rejected up front.","triggerScenarios":"Calling Animation.Play with an IterationCount constructed from a ulong greater than long.MaxValue (9223372036854775807) and RepeatType.Many.","commonSituations":"Parsing a huge iteration count from input; using 'Infinite' semantics incorrectly by passing an enormous number instead of IterationType.Infinite.","solutions":["Use IterationCount.Infinite (IterationType.Infinite) instead of an astronomically large number when you mean 'forever'.","Cap the parsed value at long.MaxValue before constructing the IterationCount.","Validate user-supplied iteration counts against long.MaxValue before assigning."],"exampleFix":"// before\nanimation.IterationCount = new IterationCount(ulong.MaxValue);\n\n// after\nanimation.IterationCount = IterationCount.Infinite;","handlingStrategy":"validation","validationCode":"const ulong maxLong = (ulong)long.MaxValue;\nif (ic.RepeatType == IterationType.Many && ic.Value > maxLong)\n    ic = IterationCount.Infinite;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use IterationCount.Infinite for unbounded repetition instead of huge numbers.","Validate parsed iteration counts against long.MaxValue before constructing.","Treat 'forever' semantics explicitly rather than approximating with large numbers."],"tags":["animation","validation","numeric-overflow","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}