peass-ng/PEASS-ng · error · ArgumentException
Exception of type 'System.ArgumentException' was thrown.
Error message
Exception of type 'System.ArgumentException' was thrown.
What it means
CopyTo throws a plain ArgumentException when the destination array is too small: for v2 folders, arrayIndex + Count exceeds array.Length (and similarly for the v1 list). There is not enough room from arrayIndex to fit all folders.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs:121
else
return item.Path == "\\";
return false;
}
/// <summary>Copies the elements of the ICollection to an Array, starting at a particular Array index.</summary>
/// <param name="array">
/// The one-dimensional Array that is the destination of the elements copied from <see cref="ICollection{T}"/>. The Array must have
/// zero-based indexing.
/// </param>
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
public void CopyTo(TaskFolder[] array, int arrayIndex)
{
if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if (array == null) throw new ArgumentNullException(nameof(array));
if (v2FolderList != null)
{
if (arrayIndex + Count > array.Length)
throw new ArgumentException();
foreach (var f in this)
array[arrayIndex++] = f;
}
else
{
if (arrayIndex + v1FolderList.Length > array.Length)
throw new ArgumentException();
v1FolderList.CopyTo(array, arrayIndex);
}
}
/// <summary>Releases all resources used by this class.</summary>
public void Dispose()
{
if (v1FolderList != null && v1FolderList.Length > 0)
{
v1FolderList[0].Dispose();
v1FolderList[0] = null;View on GitHub (pinned to 53fb989abc)
Solutions
- Size the array as collection.Count + arrayIndex
- Re-read Count immediately before CopyTo
- Use ToArray()/foreach enumeration instead
Example fix
// before var arr = new TaskFolder[10]; subFolders.CopyTo(arr, 5); // after var arr = new TaskFolder[subFolders.Count + 5]; subFolders.CopyTo(arr, 5);
Defensive patterns
Strategy: validation
Validate before calling
if (array == null || arrayIndex < 0 || arrayIndex + subFolders.Count > array.Length)
throw new ArgumentException("Destination array is too small for the folder collection."); Prevention
- Size arrays as Count + arrayIndex
- Re-read Count right before copying (collection may have changed)
- Use foreach enumeration instead of CopyTo when possible
When it happens
Trigger: CopyTo called with an array allocated for fewer elements than the collection Count, or with an arrayIndex offset that pushes past the end of the array.
Common situations: Allocating the array before subfolders were created (Count grew); copying with a non-zero offset into a tightly-sized buffer.
Related errors
- Path not found
- Specified argument was out of the range of valid values. (Pa
- Value cannot be null. (Parameter 'array')
- Resources.Cannot_Create_Directory
- Network path is not allowed for directory junction: [{0}]
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/c577477841eecb4f.
Report an issue: GitHub.