dotnet/wpf · error · ArgumentNullException
DecimalKeyFrameCollection
Error message
DecimalKeyFrameCollection[{0}] What it means
DecimalKeyFrameCollection's public indexer setter throws ArgumentNullException when null is assigned, with the parameter name "DecimalKeyFrameCollection[{index}]" identifying the slot. Every element must be a non-null DecimalKeyFrame.
Solutions
- Assign a valid DecimalKeyFrame instance instead of null
- Use RemoveAt(index) to remove the slot
- Null-check the key frame before assigning
- Repair the data source so it never supplies null key frames
Example fix
// before keyFrames[2] = null; // ArgumentNullException // after if (frame != null) keyFrames[2] = frame; else keyFrames.RemoveAt(2);
Defensive patterns
Strategy: type-guard
Validate before calling
if (frame == null) keyFrames.RemoveAt(index); else keyFrames[index] = frame;
Type guard
static bool IsValidDecimalKeyFrame(DecimalKeyFrame frame) => frame != null;
Try / catch
try { keyFrames[i] = frame; }
catch (ArgumentNullException ex) when (ex.ParamName == $"DecimalKeyFrameCollection[{i}]") { /* remove the slot or substitute a default frame */ } Prevention
- Null-check before indexer writes
- RemoveAt instead of null assignment
- Sanitize bound collections against null entries
When it happens
Trigger: Executing decimalKeyFrames[i] = null, or downstream paths that assign a null key frame into an existing index of the collection.
Common situations: Data-bound sources producing null items; clear-by-assignment patterns; deserialization gaps yielding null entries.
Related errors
- ColorKeyFrameCollection
- Animation_ChildMustBeKeyFrame
- DoubleKeyFrameCollection
- [[instance.TypeName]]KeyFrameCollection
- Int16KeyFrameCollection
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/09060a0585304e42.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/DecimalKeyFrameCollection.cs:466
}
}
/// <summary>
/// Gets or sets the DecimalKeyFrame at a given index.
/// </summary>
public DecimalKeyFrame this[int index]
{
get
{
ReadPreamble();
return _keyFrames[index];
}
set
{
if (value == null)
{
throw new ArgumentNullException(String.Format(CultureInfo.InvariantCulture, "DecimalKeyFrameCollection[{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)