egametang/ET · error · ArgumentException

Arg_ArrayPlusOffTooSmall

Error message

Arg_ArrayPlusOffTooSmall

What it means

Standard .NET BCL argument error from SortedSet<T>.CopyTo: the destination array is too small to hold the set starting at the given index, i.e. array.Length - index < Count. Raised after the index-range check passes.

Source

Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Collection/SortedSet.cs:708

            if (array.Rank != 1)
            {
                throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
            }

            if (array.GetLowerBound(0) != 0)
            {
                throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array));
            }

            if (index < 0 || index > array.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index);
            }

            if (array.Length - index < Count)
            {
                throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
            }

            T[] tarray = array as T[];
            if (tarray != null)
            {
                CopyTo(tarray, index);
            }
            else
            {
                object[] objects = array as object[];
                if (objects == null)
                {
                    throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array));
                }

                try
                {
                    InOrderTreeWalk(node =>

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Allocate the destination with at least Count elements: `var arr = new T[set.Count]; set.CopyTo(arr, 0);`.
  2. If using an offset, ensure array.Length - index >= Count.
  3. Use ToArray() when you just need a correctly sized snapshot.

Example fix

// before
var dest = new T[3];
set.CopyTo(dest, 0); // throws if set.Count > 3
// after
var dest = new T[set.Count];
set.CopyTo(dest, 0);
Defensive patterns

Strategy: validation

Validate before calling

T[] arr = new T[set.Count]; // always sized to Count
set.CopyTo(arr, 0);

Prevention

When it happens

Trigger: Passing a destination array shorter than the set's Count (minus the offset), or a non-zero index that leaves insufficient remaining slots, e.g. copying 10 elements into an array of length 5, or into index 8 of a length-10 array.

Common situations: Assuming Count when allocating; reusing a shared buffer sized for a previous, smaller set; subtracting an offset incorrectly.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/7b362a87b71b19f6. Report an issue: GitHub.