{"record":{"id":"89918cae00e5107d","repo":"peass-ng/PEASS-ng","slug":"the-array-and-none-of-the-values-passed-as-paramet","errorCode":null,"errorMessage":"The array and none of the values passed as parameters may be `null`.","messagePattern":"The array and none of the values passed as parameters may be `null`\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs","lineNumber":1477,"sourceCode":"        /// false for the task.\n        /// </para>\n        /// <para>If RunEx is invoked from a disabled task, it will return <c>null</c> and the task will not be run.</para>\n        /// </remarks>\n        /// <exception cref=\"NotV1SupportedException\">Not supported under Task Scheduler 1.0.</exception>\n        /// <example>\n        /// <code lang=\"cs\">\n        ///<![CDATA[\n        /// // Run the current task with a parameter as a different user and ignoring any of the conditions.\n        /// var runningTask = myTaskInstance.RunEx(TaskRunFlags.IgnoreConstraints, 0, \"DOMAIN\\\\User\", \"info\");\n        /// Console.Write(string.Format(\"Running task's current action is {0}.\", runningTask.CurrentAction));\n        ///]]>\n        /// </code>\n        /// </example>\n        public RunningTask RunEx(TaskRunFlags flags, int sessionID, string user, params string[] parameters)\n        {\n            if (v2Task == null) throw new NotV1SupportedException();\n            if (parameters == null || parameters.Any(s => s == null))\n                throw new ArgumentNullException(nameof(parameters), \"The array and none of the values passed as parameters may be `null`.\");\n            if (parameters.Length > 32)\n                throw new ArgumentOutOfRangeException(nameof(parameters), \"A maximum of 32 parameters can be supplied to RunEx.\");\n            if (TaskService.HighestSupportedVersion < TaskServiceVersion.V1_5 && parameters.Any(p => (p?.Length ?? 0) >= 260))\n                throw new ArgumentOutOfRangeException(nameof(parameters), \"On systems prior to Windows 10, no individual parameter may be more than 260 characters.\");\n            var irt = v2Task.RunEx(parameters.Length == 0 ? null : parameters, (int)flags, sessionID, user);\n            return irt != null ? new RunningTask(TaskService, v2Task, irt) : null;\n        }\n\n        /// <summary>\n        /// Applies access control list (ACL) entries described by a <see cref=\"TaskSecurity\"/> object to the file described by the current\n        /// <see cref=\"Task\"/> object.\n        /// </summary>\n        /// <param name=\"taskSecurity\">\n        /// A <see cref=\"TaskSecurity\"/> object that describes an access control list (ACL) entry to apply to the current task.\n        /// </param>\n        /// <example>\n        /// <para>Give read access to all authenticated users for a task.</para>\n        /// <code lang=\"cs\">","sourceCodeStart":1459,"sourceCodeEnd":1495,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs#L1459-L1495","documentation":"Task.RunEx() rejects a null parameters array or any null element inside it with an ArgumentNullException. The native IRegisteredTask::RunEx requires a valid string array, so the wrapper pre-validates the input.","triggerScenarios":"Calling task.RunEx(flags, sessionID, user, null) or task.RunEx(flags, sessionID, user, \"a\", null) — i.e. the array itself is null or contains at least one null string.","commonSituations":"Building the parameter list dynamically from variables/config where one value is null; passing an uninitialized array; LINQ projections producing null entries.","solutions":["Ensure the params array and every element are non-null before calling RunEx","Filter or replace nulls: parameters.Where(p => p != null)","Coalesce nulls to empty strings if an empty argument is acceptable","Validate user/session inputs that feed the array so they cannot be null"],"exampleFix":"// before\ntask.RunEx(TaskRunFlags.Default, 0, user, arg1, arg2); // arg2 may be null\n// after\ntask.RunEx(TaskRunFlags.Default, 0, user, arg1 ?? \"\", arg2 ?? \"\");","handlingStrategy":"validation","validationCode":"bool valid = parameters != null && parameters.All(p => p != null);\nif (!valid) throw new ArgumentException(\"parameters array and elements must be non-null\");","typeGuard":"bool HasNoNulls(string[]? p) => p != null && Array.TrueForAll(p, s => s != null);","tryCatchPattern":"try { task.RunEx(flags, sid, user, parameters); }\ncatch (ArgumentNullException) { parameters = parameters?.Where(s => s != null).ToArray() ?? Array.Empty<string>(); }","preventionTips":["Coalesce nullable values with ?? \"\" before building the array","Validate dynamic argument lists before passing to RunEx"],"tags":["taskscheduler","argumentnull","validation","csharp"],"backgroundTag":"null-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}