{"record":{"id":"245b1ec2b6500161","repo":"AvaloniaUI/Avalonia","slug":"keyframe-value-can-t-be-null","errorCode":null,"errorMessage":"KeyFrame value can't be null.","messagePattern":"KeyFrame value can't be null\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/AnimatorKeyFrame.cs","lineNumber":66,"sourceCode":"\n            if (value is BindingBase binding)\n            {\n                return Bind(ValueProperty, binding, targetControl);\n            }\n            else\n            {\n                return Bind(ValueProperty, Observable.SingleValue(value).ToBinding(), targetControl);\n            }\n        }\n\n        [RequiresUnreferencedCode(TrimmingMessages.TypeConversionRequiresUnreferencedCodeMessage)]\n        public T GetTypedValue<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>()\n        {\n            var typeConv = TypeDescriptor.GetConverter(typeof(T));\n\n            if (Value == null)\n            {\n                throw new ArgumentNullException($\"KeyFrame value can't be null.\");\n            }\n            if(Value is T typedValue)\n            {\n                return typedValue;\n            }\n            if (!typeConv.CanConvertTo(Value.GetType()))\n            {\n                throw new InvalidCastException($\"KeyFrame value doesnt match property type.\");\n            }\n\n            return (T)typeConv.ConvertTo(Value, typeof(T))!;\n        }\n\n        internal override void BuildDebugDisplay(StringBuilder builder, bool includeContent)\n        {\n            base.BuildDebugDisplay(builder, includeContent);\n            DebugDisplayHelper.AppendOptionalValue(builder, nameof(Property), Property, includeContent);\n            DebugDisplayHelper.AppendOptionalValue(builder, nameof(Cue), Cue, includeContent);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/AnimatorKeyFrame.cs#L48-L84","documentation":"Thrown by AnimatorKeyFrame.GetTypedValue<T>() when the key frame's Value is null. The method needs a concrete value to type-convert into the animator's target type T, so a null value is treated as an argument error.","triggerScenarios":"Calling GetTypedValue<T>() on an AnimatorKeyFrame whose Value property was never set or was explicitly set to null.","commonSituations":"XAML KeyFrame missing its value child/setter; binding a key frame value to a source that yielded null; programmatic key frame creation where Value was skipped.","solutions":["Provide a non-null Value on the AnimatorKeyFrame (via XAML setter or code).","Ensure any binding feeding the key frame Value never produces null (use FallbackValue).","Validate key frames for null Value before running the animation."],"exampleFix":"// before\nvar kf = new AnimatorKeyFrame { Cue = new Cue(0d) }; // Value omitted\n\n// after\nvar kf = new AnimatorKeyFrame { Cue = new Cue(0d), Value = 0d };","handlingStrategy":"validation","validationCode":"foreach (var kf in animator)\n    if (kf.Value is null)\n        throw new InvalidOperationException($\"KeyFrame at {kf.Cue} has a null Value.\");","typeGuard":"static bool HasValue(AnimatorKeyFrame kf) => kf.Value is not null;","tryCatchPattern":null,"preventionTips":["Always supply a Value when creating an AnimatorKeyFrame.","Use FallbackValue on key-frame bindings to prevent null.","Validate key frames for null Values before running the animation."],"tags":["animation","nullable-value","keyframe","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}