{"record":{"id":"6d4d46d2f09949d1","repo":"AvaloniaUI/Avalonia","slug":"animation-has-no-key-frames","errorCode":null,"errorMessage":"Animation has no key frames","messagePattern":"Animation has no key frames","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Rendering/Composition/Animations/KeyFrameAnimationInstance.cs","lineNumber":51,"sourceCode":"            AnimationDelayBehavior delayBehavior, TimeSpan delayTime,\n            PlaybackDirection direction, TimeSpan duration,\n            AnimationIterationBehavior iterationBehavior,\n            int iterationCount, AnimationStopBehavior stopBehavior) : base(target, snapshot)\n        {\n            _interpolator = interpolator;\n            _keyFrames = keyFrames;\n            _finalValue = finalValue;\n            _delayBehavior = delayBehavior;\n            _delayTime = delayTime;\n            _direction = direction;\n            _duration = duration;\n            _iterationBehavior = iterationBehavior;\n            _iterationCount = iterationCount;\n            _stopBehavior = stopBehavior;\n            if (_iterationBehavior == AnimationIterationBehavior.Count)\n                _totalDuration = delayTime.Add(TimeSpan.FromTicks(iterationCount * _duration.Ticks));\n            if (_keyFrames.Length == 0)\n                throw new InvalidOperationException(\"Animation has no key frames\");\n            if(_duration.Ticks <= 0)\n                throw new InvalidOperationException(\"Invalid animation duration\");\n        }\n\n\n        protected override ExpressionVariant EvaluateCore(TimeSpan now, ExpressionVariant currentValue)\n        {\n            var starting = ExpressionVariant.Create(_startingValue);\n            var ctx = new ExpressionEvaluationContext\n            {\n                Parameters = Parameters,\n                Target = TargetObject,\n                CurrentValue = currentValue,\n                FinalValue = _finalValue ??  starting,\n                StartingValue = starting,\n                ForeignFunctionInterface = BuiltInExpressionFfi.Instance\n            };\n            var elapsed = now - _startedAt;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Rendering/Composition/Animations/KeyFrameAnimationInstance.cs#L33-L69","documentation":"Thrown by the KeyFrameAnimationInstance constructor when the keyFrames array is empty. An animation instance cannot evaluate without at least one key frame to interpolate, so construction is treated as a programmer error (InvalidOperationException) rather than a silent no-op.","triggerScenarios":"Starting a KeyFrameAnimation via CompositionObject.StartAnimation before inserting any key frames (no InsertExpressionKeyFrame / InsertKeyFrame calls). The animation's KeyFrames collection is empty when the instance is built.","commonSituations":"Building an animation dynamically where the key-frame loop added nothing (filtered out, empty data source); copy-paste of an animation definition with the key-frame lines removed; conditional that skipped all InsertKeyFrame calls.","solutions":["Insert at least one key frame before StartAnimation: anim.InsertKeyFrame(0f, value).","Guard: only start the animation if you have added key frames.","Check a data-driven animation builder returns at least one frame before binding it."],"exampleFix":"// before\nvar anim = compositor.CreateScalarKeyFrameAnimation();\nanim.Duration = TimeSpan.FromMilliseconds(500);\nvisual.StartAnimation(\"Opacity\", anim); // throws: no key frames\n// after\nvar anim = compositor.CreateScalarKeyFrameAnimation();\nanim.Duration = TimeSpan.FromMilliseconds(500);\nanim.InsertKeyFrame(0f, 0f);\nanim.InsertKeyFrame(1f, 1f);\nvisual.StartAnimation(\"Opacity\", anim);","handlingStrategy":"validation","validationCode":"if (anim has no key frames) { /* add at least one */ anim.InsertKeyFrame(0f, value); }\nvisual.StartAnimation(\"Prop\", anim);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always insert at least one key frame before StartAnimation.","For data-driven animations, assert the frame list is non-empty before binding.","Unit-test animation builders with empty inputs."],"tags":["animation","composition","invalid-operation","key-frames","lifecycle"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}