dotnet/wpf · error · ArgumentNullException
Int32KeyFrameCollection
Error message
Int32KeyFrameCollection[{0}] What it means
The Int32KeyFrameCollection indexer setter throws ArgumentNullException whose message is the formatted string 'Int32KeyFrameCollection[{index}]' when a null key frame is assigned at an index. Null key frames are not permitted in the collection.
Solutions
- Check the key frame for null before assigning into the collection.
- Only add Int32KeyFrame instances that were successfully constructed.
- Log/validate the source of the null frame upstream.
Example fix
// before keyFrames[0] = GetFrame(); // may return null // after var frame = GetFrame(); if (frame != null) keyFrames[0] = frame;
Defensive patterns
Strategy: type-guard
Validate before calling
if (frame == null)
throw new InvalidOperationException($"No key frame available for index {index}; refusing to insert null into Int32KeyFrameCollection."); Type guard
bool IsValidFrame(Int32KeyFrame f) => f != null;
Try / catch
try { keyFrames[index] = frame; }
catch (ArgumentNullException ex) when (ex.Message.Contains("Int32KeyFrameCollection[")) {
// substitute a valid default key frame or log and skip
} Prevention
- Null-check frames from factories/lookups before inserting
- Initialize key frame collections with concrete instances
- Add unit tests covering frame collection construction with generated data
When it happens
Trigger: Executing keyFrames[index] = null; on an Int32KeyFrameCollection.
Common situations: Programmatic construction of key-frame collections where a frame variable is unexpectedly null; deserialization or data-binding producing null frames.
Related errors
- Int64KeyFrameCollection
- PointKeyFrameCollection
- RectKeyFrameCollection
- ColorKeyFrameCollection
- DecimalKeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a317b085c206897e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/Int32KeyFrameCollection.cs:466
}
}
/// <summary>
/// Gets or sets the Int32KeyFrame at a given index.
/// </summary>
public Int32KeyFrame this[int index]
{
get
{
ReadPreamble();
return _keyFrames[index];
}
set
{
if (value == null)
{
throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "Int32KeyFrameCollection[{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)