dotnet/wpf · error · ArgumentNullException

Int16KeyFrameCollection

Error message

Int16KeyFrameCollection[{0}]

What it means

The Int16KeyFrameCollection indexer setter throws ArgumentNullException with message "Int16KeyFrameCollection[{index}]" when a null Int16KeyFrame is assigned at the specified index. Null key frames are rejected to preserve collection invariants.

Solutions

  1. Check for null before assigning a frame into the collection
  2. Filter null entries out before populating KeyFrames
  3. Use a valid default frame instead of a null placeholder

Example fix

// before
frames[i] = BuildFrame(i); // can be null
// after
var f = BuildFrame(i);
if (f != null) frames[i] = f;
Defensive patterns

Strategy: type-guard

Validate before calling

if (frame == null) throw new ArgumentNullException(nameof(frame));
collection[index] = frame;

Type guard

static bool IsValidFrame(Int16KeyFrame f) => f != null;

Try / catch

try { collection[index] = frame; } catch (ArgumentNullException ex) when (ex.Message.StartsWith("Int16KeyFrameCollection[")) { /* supply non-null frame */ }

Prevention

When it happens

Trigger: Executing int16KeyFrameCollection[index] = null, or an automated/XAML path inserting a null key frame at an index.

Common situations: Building key-frame collections from data where entries can be null; factory/helper methods returning null frames that are then indexed into the collection.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/9c8e0aace135ed4c. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Int16KeyFrameCollection.cs:466

            }
        }

        /// <summary>
        /// Gets or sets the Int16KeyFrame at a given index.
        /// </summary>
        public Int16KeyFrame this[int index]
        {
            get
            {
                ReadPreamble();

                return _keyFrames[index];
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "Int16KeyFrameCollection[{0}]", index));
                }

                WritePreamble();

                if (value != _keyFrames[index])
                {
                    OnFreezablePropertyChanged(_keyFrames[index], value);
                    _keyFrames[index] = value;

                    Debug.Assert(_keyFrames[index] != null);

                    WritePostscript();
                }
            }
        }

        #endregion
    }

View on GitHub (pinned to 81131a70a4)