InvalidCastException: Specified cast is not valid.

I get this error When I put keyframe from sprite sheet. I don’t know why

InvalidCastException: Specified cast is not valid.
UnityEditorInternal.AnimationRecording.AddKey (UnityEditorInternal.IAnimationRecordingState state, UnityEditor.EditorCurveBinding binding, System.Type type, System.Object previousValue, System.Object currentValue) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs:513)
UnityEditorInternal.AnimationRecording.ProcessModifications (UnityEditorInternal.IAnimationRecordingState state, UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs:420)
UnityEditorInternal.AnimationRecording.Process (UnityEditorInternal.IAnimationRecordingState state, UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationRecording.cs:455)
UnityEditorInternal.AnimationWindowControl.ProcessAutoKey (UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs:787)
UnityEditorInternal.AnimationWindowControl.PostprocessAnimationRecordingModifications (UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs:771)
UnityEditor.Undo.InvokePostprocessModifications (UnityEditor.UndoPropertyModification[] modifications) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Undo/Undo.bindings.cs:274)

does anyone know the solution for this?

Unity 2022.1.14f1

Won’t anyone help? It’s important

Hello ! This bug is still here ! I’m using Unity 2022.1.16f1 for a project with my students. The school installed this version. If you try to add a keyframe (in a animation) changing the sprite of a sprite renderer, it will give this error.

The solution i found is to manually add a keyframe of type sprite renderer type. Then, if you try to modify the sprite again, the keyframe will add correctly. There is no sense …

I hope it’s fixed in the other versions !