{"record":{"id":"4204dadc9de67563","repo":"AvaloniaUI/Avalonia","slug":"key-frame-key","errorCode":null,"errorMessage":"Key frame key","messagePattern":"Key frame key","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Rendering/Composition/Animations/KeyFrames.cs","lineNumber":18,"sourceCode":"using System;\nusing System.Collections.Generic;\nusing Avalonia.Animation.Easings;\nusing Avalonia.Rendering.Composition.Expressions;\n\nnamespace Avalonia.Rendering.Composition.Animations\n{\n    \n    /// <summary>\n    /// Collection of composition animation key frames\n    /// </summary>\n    /// <typeparam name=\"T\"></typeparam>\n    class KeyFrames<T> : List<KeyFrame<T>>, IKeyFrames\n    {\n        void Validate(float key)\n        {\n            if (key < 0 || key > 1)\n                throw new ArgumentException(\"Key frame key\");\n            if (Count > 0 && this[Count - 1].NormalizedProgressKey > key)\n                throw new ArgumentException(\"Key frame key \" + key + \" is less than the previous one\");\n        }\n        \n        public void InsertExpressionKeyFrame(float normalizedProgressKey, string value, IEasing easingFunction)\n        {\n            Validate(normalizedProgressKey);\n            Add(new KeyFrame<T>\n            {\n                NormalizedProgressKey = normalizedProgressKey,\n                Expression = Expression.Parse(value),\n                EasingFunction = easingFunction\n            });\n        }\n\n        public void Insert(float normalizedProgressKey, T value, IEasing easingFunction)\n        {\n            Validate(normalizedProgressKey);","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Rendering/Composition/Animations/KeyFrames.cs#L1-L36","documentation":"Thrown by KeyFrames<T>.Validate when a key frame's normalizedProgressKey is outside the [0,1] range. The terse message 'Key frame key' is unhelpful but means the progress key must be a normalized fraction (0 = start of animation, 1 = end).","triggerScenarios":"Calling InsertExpressionKeyFrame/InsertKeyFrame with a key like -0.1f, 1.5f, or passing a percentage (e.g. 50f instead of 0.5f).","commonSituations":"Passing a percent value (0..100) instead of a normalized value (0..1); sign error producing a negative; off-by-one where the last frame is keyed slightly above 1.","solutions":["Pass a normalized key in [0,1] (divide a percentage by 100).","Clamp: Math.Clamp(key, 0f, 1f).","Use InsertKeyFrame(1f, endValue) for the terminal frame."],"exampleFix":"// before\nanim.InsertKeyFrame(50f, value); // 50% passed as 50\n// after\nanim.InsertKeyFrame(0.5f, value);","handlingStrategy":"validation","validationCode":"float keyClamped = Math.Clamp(normalizedProgressKey, 0f, 1f);\nanim.InsertKeyFrame(keyClamped, value);","typeGuard":"static bool IsValidKey(float k) => k is >= 0f and <= 1f;","tryCatchPattern":null,"preventionTips":["Pass normalized keys in [0,1]; divide percentages by 100.","Clamp user-supplied progress values.","Use 1f for the terminal frame."],"tags":["animation","composition","key-frames","argument-validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}