HandyOrg/HandyControl · warning · ArgumentNullException
DoubleKeyFrameCollection
Error message
DoubleKeyFrameCollection[{0}] What it means
The GeometryKeyFrameCollection indexer setter rejects null values but incorrectly throws ArgumentNullException with a formatted message string ("DoubleKeyFrameCollection[{index}]") instead of (paramName, message). The exception occurs before WritePreamble, so the collection state is unchanged; the odd parameter usage is a copy-paste from WPF's DoubleKeyFrameCollection.
Solutions
- Do not assign null to collection slots; remove unwanted frames with Remove/RemoveAt instead.
- Replace a frame by constructing a valid GeometryKeyFrame instance rather than nulling the index.
- Clear the whole collection with Clear() and re-add frames if many need replacing.
Example fix
// before
keyFrames[0] = null;
// after
keyFrames.RemoveAt(0); // or keyFrames[0] = new GeometryKeyFrame { Value = ... }; Defensive patterns
Strategy: validation
Validate before calling
if (value != null)
keyFrames[index] = value;
else
keyFrames.RemoveAt(index); Type guard
static bool IsValidKeyFrame(HandyControl.Media.Animation.GeometryKeyFrame frame) => frame != null;
Try / catch
try { keyFrames[i] = frame; } catch (ArgumentNullException) { // frame was null; remove the slot instead
keyFrames.RemoveAt(i); } Prevention
- Never assign null into GeometryKeyFrameCollection; use Remove/RemoveAt to drop frames.
- Filter null frames out before populating the collection from dynamic data.
- Use Clear() plus re-add for bulk replacement instead of nulling slots.
When it happens
Trigger: Assigning null into the collection: keyFrames[i] = null; on a GeometryKeyFrameCollection used by GeometryAnimationUsingKeyFrames.
Common situations: Dynamically rebuilding key frames in code where a slot is cleared with null; generic collection-filling code that assigns null placeholders.
Related errors
- owner
- Animation_ChildMustBeKeyFrame
- The parameter can not be either null or empty.
- The parameter can not be either null or empty or consist…
- ExceptionStringTable.DuplicateItemInCollectionExceptionMessa…
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/d0f833a927203e2d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/HandyControl_Shared/Media/Animation/GeometryKeyFrameCollection.cs:288
object IList.this[int index]
{
get => this[index];
set => this[index] = (GeometryKeyFrame) value;
}
public GeometryKeyFrame 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;
WritePostscript();
}
}
}
public bool IsReadOnly
{
get
{View on GitHub (pinned to 2c0875ebd6)