{"record":{"id":"688d2276d3eb553b","repo":"dotnet/wpf","slug":"bytekeyframecollection-index","errorCode":null,"errorMessage":"ByteKeyFrameCollection[{index}]","messagePattern":"ByteKeyFrameCollection\\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ByteKeyFrameCollection.cs","lineNumber":466,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// Gets or sets the ByteKeyFrame at a given index.\n        /// </summary>\n        public ByteKeyFrame 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, \"ByteKeyFrameCollection[{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":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/ByteKeyFrameCollection.cs#L448-L484","documentation":"The indexer setter of ByteKeyFrameCollection throws ArgumentNullException (message \"ByteKeyFrameCollection[{index}]\") when null is assigned into the collection at an index. Every slot in the collection must hold a concrete ByteKeyFrame instance.","triggerScenarios":"Assigning null via the indexer: byteKeyFrameCollection[i] = null; or a binding/generated code path that writes a null ByteKeyFrame into the collection.","commonSituations":"Failed resource resolution for a key frame in XAML, or code that computes key frames dynamically and can produce null entries.","solutions":["Assign a valid ByteKeyFrame (e.g. new LinearByteKeyFrame((byte)10, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)))) instead of null","Null-check before inserting and skip or substitute a default key frame","Verify XAML resources for key frames resolve to the correct type"],"exampleFix":"// before\nframes[0] = MakeKeyFrame(); // may return null\n// after\nvar kf = MakeKeyFrame();\nframes[0] = kf ?? new DiscreteByteKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.Zero));","handlingStrategy":"validation","validationCode":"if (frame == null) throw new ArgumentException(\"Key frame cannot be null\", nameof(frame));\nbyteKeyFrameCollection[index] = frame;","typeGuard":"static bool IsValidKeyFrame(ByteKeyFrame f) => f != null;","tryCatchPattern":"try { collection[index] = frame; }\ncatch (ArgumentNullException ex) { /* message names the index; supply a valid ByteKeyFrame */ }","preventionTips":["Never assign null into key-frame collections; use typed Add methods","Null-check dynamically computed key frames before insertion","Confirm XAML resource references resolve to ByteKeyFrame instances"],"tags":["wpf","animation","argument-null","keyframe-collection"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}