{"record":{"id":"51c64fac075ae38d","repo":"dotnet/wpf","slug":"booleankeyframecollection-index","errorCode":null,"errorMessage":"BooleanKeyFrameCollection[{index}]","messagePattern":"BooleanKeyFrameCollection\\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/BooleanKeyFrameCollection.cs","lineNumber":466,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// Gets or sets the BooleanKeyFrame at a given index.\n        /// </summary>\n        public BooleanKeyFrame 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, \"BooleanKeyFrameCollection[{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/BooleanKeyFrameCollection.cs#L448-L484","documentation":"The indexer setter of BooleanKeyFrameCollection throws ArgumentNullException when a caller assigns null into the collection at a given index. The exception's message is built as \"BooleanKeyFrameCollection[{index}]\" and passed as the paramName-style argument, identifying the position that received null. Key frame collections require a concrete BooleanKeyFrame instance at every slot.","triggerScenarios":"Assigning null via the indexer: booleanKeyFrameCollection[i] = null; or any data-bound/generated code path that writes a null key frame into the collection.","commonSituations":"XAML or code that builds a key-frame animation where a resource fails to resolve to a BooleanKeyFrame, or computed values that yield null before being inserted.","solutions":["Assign a valid non-null BooleanKeyFrame instance (e.g. new DiscreteBooleanKeyFrame(true, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)))) instead of null","Check the value for null before inserting and skip or substitute a default key frame","If coming from XAML binding, verify the bound resource/key actually resolves to a BooleanKeyFrame"],"exampleFix":"// before\nframes[0] = GetKeyFrame(); // may return null\n// after\nvar kf = GetKeyFrame();\nframes[0] = kf ?? new DiscreteBooleanKeyFrame(false, KeyTime.FromTimeSpan(TimeSpan.Zero));","handlingStrategy":"validation","validationCode":"if (frame == null) throw new ArgumentException(\"Key frame cannot be null\", nameof(frame));\nbooleanKeyFrameCollection[index] = frame;","typeGuard":"static bool IsValidKeyFrame(BooleanKeyFrame f) => f != null;","tryCatchPattern":"try { collection[index] = frame; }\ncatch (ArgumentNullException ex) { /* ex.ParamName contains \"BooleanKeyFrameCollection[i]\"; supply a valid key frame or skip */ }","preventionTips":["Never assign null into key-frame collections; use the typed Add methods","Null-check key frames produced by factories or resource lookups before insertion","Prefer building key frames with object initializers so nulls fail fast"],"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-21T21:30:21.729Z"}