{"record":{"id":"105035ee4c90cbf7","repo":"peass-ng/PEASS-ng","slug":"value-cannot-be-null-parameter-array","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'array')","messagePattern":"Value cannot be null\\. \\(Parameter 'array'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs","lineNumber":117,"sourceCode":"                for (var i = v2FolderList.Count; i > 0; i--)\n                    if (string.Equals(item.Path, v2FolderList[i].Path, StringComparison.CurrentCultureIgnoreCase))\n                        return true;\n            }\n            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        {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs#L99-L135","documentation":"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.","triggerScenarios":"Calling subFolders.CopyTo(null, 0), or passing an array variable that was never initialized.","commonSituations":"Copy/paste refactor where the array allocation was removed; conditional allocation skipped on some code path.","solutions":["Allocate the destination array before CopyTo (size >= Count)","Check for null before calling","Use foreach/ToArray instead of manual CopyTo"],"exampleFix":"// before\nTaskFolder[] arr = null;\nsubFolders.CopyTo(arr, 0);\n// after\nvar arr = new TaskFolder[subFolders.Count];\nsubFolders.CopyTo(arr, 0);","handlingStrategy":"validation","validationCode":"if (array == null) throw new ArgumentNullException(nameof(array));\nif (array.Length < subFolders.Count) throw new ArgumentException(\"Array too small.\");","typeGuard":null,"tryCatchPattern":"try { subFolders.CopyTo(array, 0); }\ncatch (ArgumentNullException) { array = new TaskFolder[subFolders.Count]; subFolders.CopyTo(array, 0); }","preventionTips":["Always allocate destination arrays with collection.Count elements","Use 'new TaskFolder[collection.Count]' idiom","Prefer LINQ ToArray()/Cast<TaskFolder>().ToArray()"],"tags":["task-scheduler","argumentnull","copyto"],"backgroundTag":"null-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}