peass-ng/PEASS-ng · error · ArgumentNullException
Value cannot be null. (Parameter 'array')
Error message
Value cannot be null. (Parameter 'array')
What it means
Null-argument guard in TaskFolderCollection.CopyTo (ICollection.CopyTo implementation): it fires when the destination array is null, before any folder enumeration happens, matching the standard .NET collection contract that a null destination array is rejected.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs:117
for (var i = v2FolderList.Count; i > 0; i--)
if (string.Equals(item.Path, v2FolderList[i].Path, StringComparison.CurrentCultureIgnoreCase))
return true;
}
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()
{View on GitHub (pinned to 53fb989abc)
Solutions
- Allocate the destination array before CopyTo (size >= Count)
- Check for null before calling
- Use foreach/ToArray instead of manual CopyTo
Example fix
// before TaskFolder[] arr = null; subFolders.CopyTo(arr, 0); // after var arr = new TaskFolder[subFolders.Count]; subFolders.CopyTo(arr, 0);
Defensive patterns
Strategy: validation
Validate before calling
if (array == null) throw new ArgumentNullException(nameof(array));
if (array.Length < subFolders.Count) throw new ArgumentException("Array too small."); Try / catch
try { subFolders.CopyTo(array, 0); }
catch (ArgumentNullException) { array = new TaskFolder[subFolders.Count]; subFolders.CopyTo(array, 0); } Prevention
- Always allocate destination arrays with collection.Count elements
- Use 'new TaskFolder[collection.Count]' idiom
- Prefer LINQ ToArray()/Cast<TaskFolder>().ToArray()
When it happens
Trigger: Calling subFolders.CopyTo(null, 0), or passing an array variable that was never initialized.
Common situations: Copy/paste refactor where the array allocation was removed; conditional allocation skipped on some code path.
Related errors
- Specified argument was out of the range of valid values. (Pa
- Exception of type 'System.ArgumentException' was thrown.
- path
- Value cannot be null. Parameter name: path
- The array and none of the values passed as parameters may be
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/105035ee4c90cbf7.
Report an issue: GitHub.