dotnet/wpf · error · ArgumentNullException
DoubleKeyFrameCollection
Error message
DoubleKeyFrameCollection[{0}] What it means
The DoubleKeyFrameCollection indexer setter throws ArgumentNullException whose message is "DoubleKeyFrameCollection[{index}]" when a null DoubleKeyFrame is assigned at the given index. Null key frames are not permitted in the collection.
Solutions
- Ensure the DoubleKeyFrame instance is non-null before assigning into the collection
- Filter nulls from source lists before building the collection
- If a placeholder is needed, use a key frame with a valid value instead of null
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 ArgumentNullException(nameof(frame)); collection[index] = frame;
Type guard
static bool IsValidFrame(DoubleKeyFrame f) => f != null;
Try / catch
try { collection[index] = frame; } catch (ArgumentNullException ex) when (ex.Message.StartsWith("DoubleKeyFrameCollection[")) { /* supply a non-null frame */ } Prevention
- Guard factory methods that may return null frames before indexing into the collection
- Filter nulls out of source data when programmatically building key-frame collections
- Use non-null placeholder key frames instead of null slots
When it happens
Trigger: Executing collection[index] = null on a DoubleKeyFrameCollection, or XAML/serialization paths inserting a null key frame at an index.
Common situations: Programmatic population of key frames where a null slipped through (e.g. a factory method returned null); data-driven construction of animations from a list containing nulls.
Related errors
- Int16KeyFrameCollection
- [[instance.TypeName]]KeyFrameCollection
- MatrixKeyFrameCollection
- ObjectKeyFrameCollection
- Point3DKeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d3aaaef8c14480a0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/DoubleKeyFrameCollection.cs:466
}
}
/// <summary>
/// Gets or sets the DoubleKeyFrame at a given index.
/// </summary>
public DoubleKeyFrame this[int index]
{
get
{
ReadPreamble();
return _keyFrames[index];
}
set
{
if (value == null)
{
throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "DoubleKeyFrameCollection[{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)