{"record":{"id":"bc29938c18dc03d7","repo":"dotnet/wpf","slug":"instance-typename-keyframecollection-0","errorCode":null,"errorMessage":"[[instance.TypeName]]KeyFrameCollection[{0}]","messagePattern":"\\[\\[instance\\.TypeName\\]\\]KeyFrameCollection\\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/KeyFrameCollectionTemplate.cs","lineNumber":526,"sourceCode":"                                        }\n                                    }\n                                    \n                                    /// <summary>\n                                    /// Gets or sets the [[instance.TypeName]]KeyFrame at a given index.\n                                    /// </summary>\n                                    public [[instance.TypeName]]KeyFrame this[int index]\n                                    {\n                                        get\n                                        {\n                                            ReadPreamble();\n                                            \n                                            return _keyFrames[index];\n                                        }\n                                        set\n                                        {\n                                            if (value == null)\n                                            {\n                                                throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, \"[[instance.TypeName]]KeyFrameCollection[{0}]\", index));\n                                            }\n                                            \n                                            WritePreamble();\n                                            \n                                            if (value != _keyFrames[index])\n                                            {\n                                                OnFreezablePropertyChanged(_keyFrames[index], value);\n                                                _keyFrames[index] = value;\n                                                                    \n                                                Debug.Assert(_keyFrames[index] != null);\n                                                \n                                                WritePostscript();\n                                            }\n                                        }\n                                    }\n                                    \n                                    #endregion\n                                }","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/KeyFrameCollectionTemplate.cs#L508-L544","documentation":"Thrown by a KeyFrameCollectionTemplate-generated KeyFrameCollection indexer setter when value is null — the collection indexers do not permit null key frames. This is a codegen template emitting an ArgumentNullException naming the index position.","triggerScenarios":"Assigning null into a key-frame collection via the indexer, e.g. collection[0] = null, or databinding/serialization writing null into the list.","commonSituations":"Programmatic key-frame animation construction (DoubleKeyFrameCollection, ColorKeyFrameCollection) with an uninitialized frame variable; XAML or tooling emitting a null child; deserialization of incomplete animation markup.","solutions":["Ensure the key frame instance is constructed before assigning: collection[i] = new LinearDoubleKeyFrame(...).","Remove the index instead of setting null: use RemoveAt(i) to delete an entry.","Guard loops/serialization that may produce null frames before touching the collection."],"exampleFix":"// before\ndoubleKeyFrames[0] = null; // trying to clear the frame\n// after\ndoubleKeyFrames.RemoveAt(0);","handlingStrategy":"validation","validationCode":"if (frame == null) throw new InvalidOperationException($\"Key frame at index {i} is null; construct it before assignment.\");\ncollection[i] = frame;","typeGuard":"static bool IsValidFrame<T>(T frame) where T : class => frame != null;","tryCatchPattern":"try { collection[i] = frame; } catch (ArgumentNullException ex) when (ex.ParamName == $\"{i}\" || ex.Message.Contains($\"[{i}]\")) { log.Warn($\"Skipping null key frame at index {i}\"); }","preventionTips":["Initialize key frame objects before adding/assigning them to collections.","Use RemoveAt(index) instead of assigning null to remove entries.","Validate deserialized animation data for null frames before populating collections."],"tags":["wpf","animation","keyframes","null"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}