peass-ng/PEASS-ng · error · ArgumentOutOfRangeException

Array has insufficient capacity to support copy.

Error message

Array has insufficient capacity to support copy.

What it means

ICollection<KeyValuePair<string, string>>.CopyTo throws ArgumentException when the KeyValuePair destination array is too small to receive all name/value pairs (insufficient capacity given the array length and start index). The destination array sizing, not the collection, is at fault.

Solutions

  1. Size the destination array to at least Count + arrayIndex.
  2. Copy via LINQ (Select + ToArray) instead of CopyTo to avoid manual sizing.
  3. Copy in batches if the destination array is fixed-size.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/NamedValueCollection.cs:602 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/8d4eee12eee62dc7. Report an issue: GitHub.

Appendix: source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/NamedValueCollection.cs:602

                }
            }
            return false;
        }

        bool IDictionary<string, string>.ContainsKey(string key) => Names.Contains(key);

        void ICollection<KeyValuePair<string, string>>.Add(KeyValuePair<string, string> item)
        {
            Add(item.Key, item.Value);
        }

        bool ICollection<KeyValuePair<string, string>>.Contains(KeyValuePair<string, string> item) =>
            ((ICollection<NameValuePair>)this).Contains(new NameValuePair(item.Key, item.Value));

        void ICollection<KeyValuePair<string, string>>.CopyTo(KeyValuePair<string, string>[] array, int arrayIndex)
        {
            if (array.Length < Count + arrayIndex)
                throw new ArgumentOutOfRangeException(nameof(array), @"Array has insufficient capacity to support copy.");
            foreach (var item in ((IEnumerable<KeyValuePair<string, string>>)this))
                array[arrayIndex++] = item;
        }

        bool ICollection<KeyValuePair<string, string>>.Remove(KeyValuePair<string, string> item) =>
            ((ICollection<NameValuePair>)this).Remove(new NameValuePair(item.Key, item.Value));

        IEnumerator<KeyValuePair<string, string>> IEnumerable<KeyValuePair<string, string>>.GetEnumerator()
        {
            foreach (var nvp in this)
                yield return new KeyValuePair<string, string>(nvp.Name, nvp.Value);
        }
    }
}

View on GitHub (pinned to 53fb989abc)