dotnet/wpf · error · ArgumentNullException
PointKeyFrameCollection
Error message
PointKeyFrameCollection[{0}] What it means
PointKeyFrameCollection's this[index] setter throws ArgumentNullException with the message "PointKeyFrameCollection[{0}]" (index interpolated) when a null PointKeyFrame is stored into the collection. Unlike most ArgumentNullExceptions the message is the formatted parameter name, so the exception's message looks like a collection indexer label. The collection enforces that every slot holds a real key frame.
Solutions
- Assign a valid PointKeyFrame instance instead of null.
- Use RemoveAt(index) to remove an entry rather than setting the slot to null.
- Null-check the key frame variable before indexing into the collection.
- Catch ArgumentNullException around collection writes if items come from external data.
Example fix
// before keyFrames[0] = null; // after keyFrames.RemoveAt(0); // or keyFrames[0] = new LinearPointKeyFrame(new Point(10,10), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)));
Defensive patterns
Strategy: type-guard
Validate before calling
if (frame != null) collection[index] = frame; else collection.RemoveAt(index);
Type guard
static bool IsStorableKeyFrame(PointKeyFrame f) => f != null;
Try / catch
try { collection[i] = frame; }
catch (ArgumentNullException) { collection.RemoveAt(i); } Prevention
- Use RemoveAt instead of assigning null
- Null-check key frame variables before writing
- Validate deserialized collections for null entries
When it happens
Trigger: Assigning null via the indexer: myKeyFrameCollection[i] = null; or via databinding/tools that write null into a collection item slot.
Common situations: Programmatically building key frame animations where a key frame variable was never created; templated/generic code that clears items by assigning null instead of calling RemoveAt; deserialization producing null entries.
Related errors
- Int32KeyFrameCollection
- Int64KeyFrameCollection
- RectKeyFrameCollection
- ColorKeyFrameCollection
- DecimalKeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3d6e1c4096553027.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/PointKeyFrameCollection.cs:466
}
}
/// <summary>
/// Gets or sets the PointKeyFrame at a given index.
/// </summary>
public PointKeyFrame this[int index]
{
get
{
ReadPreamble();
return _keyFrames[index];
}
set
{
if (value == null)
{
throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "PointKeyFrameCollection[{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)