dotnet/wpf · error · ArgumentNullException
MatrixKeyFrameCollection
Error message
MatrixKeyFrameCollection[{0}] What it means
The MatrixKeyFrameCollection indexer setter throws ArgumentNullException when a null key frame is assigned. The exception's message ( paramName) is the formatted string "MatrixKeyFrameCollection[index]", identifying the collection position rather than a parameter name.
Solutions
- Guard the value for null before assigning into the collection
- Only add non-null MatrixKeyFrame instances (use Add, which also validates)
- If a slot must be 'empty', remove the frame instead of assigning null
Example fix
// before
keyFrames[0] = GetFrameMaybeNull();
// after
var frame = GetFrameMaybeNull();
if (frame == null) throw new InvalidOperationException("frame required");
keyFrames[0] = frame; Defensive patterns
Strategy: validation
Validate before calling
if (frame == null) throw new ArgumentException($"MatrixKeyFrameCollection[{index}] requires a non-null frame");
collection[index] = frame; Type guard
bool IsValidFrame(MatrixKeyFrame f) => f != null;
Try / catch
try { collection[index] = frame; }
catch (ArgumentNullException ex) when (ex.ParamName?.StartsWith("MatrixKeyFrameCollection[") == true) { /* supply a valid frame or remove the slot */ } Prevention
- Null-check frames before any collection assignment
- Prefer Add over indexer assignment for new frames
- Filter nulls out of data-driven frame lists
When it happens
Trigger: Executing collection[index] = null on a MatrixKeyFrameCollection.
Common situations: Building key-frame animations from data where individual frames may be null; reflection or designer code assigning frames by index.
Related errors
- DoubleKeyFrameCollection
- Int16KeyFrameCollection
- ObjectKeyFrameCollection
- Point3DKeyFrameCollection
- [[instance.TypeName]]KeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f5e30572a8510acb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/MatrixKeyFrameCollection.cs:466
}
}
/// <summary>
/// Gets or sets the MatrixKeyFrame at a given index.
/// </summary>
public MatrixKeyFrame this[int index]
{
get
{
ReadPreamble();
return _keyFrames[index];
}
set
{
if (value == null)
{
throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "MatrixKeyFrameCollection[{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)