{"record":{"id":"c577477841eecb4f","repo":"peass-ng/PEASS-ng","slug":"exception-of-type-system-argumentexception-was-t","errorCode":null,"errorMessage":"Exception of type 'System.ArgumentException' was thrown.","messagePattern":"Exception of type 'System\\.ArgumentException' was thrown\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs","lineNumber":121,"sourceCode":"            else\n                return item.Path == \"\\\\\";\n            return false;\n        }\n\n        /// <summary>Copies the elements of the ICollection to an Array, starting at a particular Array index.</summary>\n        /// <param name=\"array\">\n        /// The one-dimensional Array that is the destination of the elements copied from <see cref=\"ICollection{T}\"/>. The Array must have\n        /// zero-based indexing.\n        /// </param>\n        /// <param name=\"arrayIndex\">The zero-based index in array at which copying begins.</param>\n        public void CopyTo(TaskFolder[] array, int arrayIndex)\n        {\n            if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));\n            if (array == null) throw new ArgumentNullException(nameof(array));\n            if (v2FolderList != null)\n            {\n                if (arrayIndex + Count > array.Length)\n                    throw new ArgumentException();\n                foreach (var f in this)\n                    array[arrayIndex++] = f;\n            }\n            else\n            {\n                if (arrayIndex + v1FolderList.Length > array.Length)\n                    throw new ArgumentException();\n                v1FolderList.CopyTo(array, arrayIndex);\n            }\n        }\n\n        /// <summary>Releases all resources used by this class.</summary>\n        public void Dispose()\n        {\n            if (v1FolderList != null && v1FolderList.Length > 0)\n            {\n                v1FolderList[0].Dispose();\n                v1FolderList[0] = null;","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"Allocating the array before subfolders were created (Count grew); copying with a non-zero offset into a tightly-sized buffer.","solutions":["Size the array as collection.Count + arrayIndex","Re-read Count immediately before CopyTo","Use ToArray()/foreach enumeration instead"],"exampleFix":"// before\nvar arr = new TaskFolder[10];\nsubFolders.CopyTo(arr, 5);\n// after\nvar arr = new TaskFolder[subFolders.Count + 5];\nsubFolders.CopyTo(arr, 5);","handlingStrategy":"validation","validationCode":"if (array == null || arrayIndex < 0 || arrayIndex + subFolders.Count > array.Length)\n    throw new ArgumentException(\"Destination array is too small for the folder collection.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size arrays as Count + arrayIndex","Re-read Count right before copying (collection may have changed)","Use foreach enumeration instead of CopyTo when possible"],"tags":["task-scheduler","argumentexception","copyto","array-size"],"backgroundTag":"destination-array-too-small","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}