stride3d/stride · error · ArgumentOutOfRangeException
ArgumentOutOfRangeException
Error message
ArgumentOutOfRangeException
What it means
Collection contract guard in SortedDictionary.KeyCollection.CopyTo: the index parameter is negative (or would place the copy out of range), so copying the keys into the destination array cannot proceed. The faulting input is the index argument.
Solutions
- Clamp or validate index >= 0 before calling CopyTo
- Recheck the offset calculation that produced the negative index
- Use index 0 when copying into a fresh array
Example fix
// before keys.CopyTo(arr, -1); // after if (index >= 0) keys.CopyTo(arr, index);
Defensive patterns
Strategy: validation
Validate before calling
if (index < 0) throw new InvalidOperationException("CopyTo index must be non-negative"); Type guard
null
Try / catch
try { keys.CopyTo(arr, index); } catch (ArgumentOutOfRangeException) { keys.CopyTo(arr, 0); } Prevention
- Validate computed offsets before CopyTo
- Clamp indices with Math.Max(0, index)
- Prefer ToArray() over index-based copying
When it happens
Trigger: Calling CopyTo with a negative index, often from a computed offset that went below zero (e.g. index -= n on a small buffer).
Common situations: Offset arithmetic bugs when filling a section of a larger array.
Related errors
- ArgumentException
- ArgumentOutOfRangeException
- BoundingVolumeBufferDownsampleLevel
- capacity too small
- Indices for Color run from 0 to 3, inclusive.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/543908c5ffa20b01.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/SortedDictionary.cs:539
{
return new Enumerator(dictionary);
}
IEnumerator IEnumerable.GetEnumerator()
{
return new Enumerator(dictionary);
}
public void CopyTo(TKey[] array, int index)
{
if (array == null)
{
throw new ArgumentNullException();
}
if (index < 0)
{
throw new ArgumentOutOfRangeException();
}
if (array.Length - index < Count)
{
throw new ArgumentException();
}
dictionary._set.InOrderTreeWalk(delegate(TreeSet<KeyValuePair<TKey, TValue>>.Node node)
{
array[index++] = node.Item.Key;
return true;
});
}
void ICollection.CopyTo(Array array, int index)
{
if (array == null)
{View on GitHub (pinned to 96fad776d2)