peass-ng/PEASS-ng · error · ArgumentNullException
The array and none of the values passed as parameters may be
Error message
The array and none of the values passed as parameters may be `null`.
What it means
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.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs:1477
/// false for the task.
/// </para>
/// <para>If RunEx is invoked from a disabled task, it will return <c>null</c> and the task will not be run.</para>
/// </remarks>
/// <exception cref="NotV1SupportedException">Not supported under Task Scheduler 1.0.</exception>
/// <example>
/// <code lang="cs">
///<![CDATA[
/// // Run the current task with a parameter as a different user and ignoring any of the conditions.
/// var runningTask = myTaskInstance.RunEx(TaskRunFlags.IgnoreConstraints, 0, "DOMAIN\\User", "info");
/// Console.Write(string.Format("Running task's current action is {0}.", runningTask.CurrentAction));
///]]>
/// </code>
/// </example>
public RunningTask RunEx(TaskRunFlags flags, int sessionID, string user, params string[] parameters)
{
if (v2Task == null) throw new NotV1SupportedException();
if (parameters == null || parameters.Any(s => s == null))
throw new ArgumentNullException(nameof(parameters), "The array and none of the values passed as parameters may be `null`.");
if (parameters.Length > 32)
throw new ArgumentOutOfRangeException(nameof(parameters), "A maximum of 32 parameters can be supplied to RunEx.");
if (TaskService.HighestSupportedVersion < TaskServiceVersion.V1_5 && parameters.Any(p => (p?.Length ?? 0) >= 260))
throw new ArgumentOutOfRangeException(nameof(parameters), "On systems prior to Windows 10, no individual parameter may be more than 260 characters.");
var irt = v2Task.RunEx(parameters.Length == 0 ? null : parameters, (int)flags, sessionID, user);
return irt != null ? new RunningTask(TaskService, v2Task, irt) : null;
}
/// <summary>
/// Applies access control list (ACL) entries described by a <see cref="TaskSecurity"/> object to the file described by the current
/// <see cref="Task"/> object.
/// </summary>
/// <param name="taskSecurity">
/// A <see cref="TaskSecurity"/> object that describes an access control list (ACL) entry to apply to the current task.
/// </param>
/// <example>
/// <para>Give read access to all authenticated users for a task.</para>
/// <code lang="cs">View on GitHub (pinned to 53fb989abc)
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
Example fix
// before task.RunEx(TaskRunFlags.Default, 0, user, arg1, arg2); // arg2 may be null // after task.RunEx(TaskRunFlags.Default, 0, user, arg1 ?? "", arg2 ?? "");
Defensive patterns
Strategy: validation
Validate before calling
bool valid = parameters != null && parameters.All(p => p != null);
if (!valid) throw new ArgumentException("parameters array and elements must be non-null"); Type guard
bool HasNoNulls(string[]? p) => p != null && Array.TrueForAll(p, s => s != null);
Try / catch
try { task.RunEx(flags, sid, user, parameters); }
catch (ArgumentNullException) { parameters = parameters?.Where(s => s != null).ToArray() ?? Array.Empty<string>(); } Prevention
- Coalesce nullable values with ?? "" before building the array
- Validate dynamic argument lists before passing to RunEx
When it happens
Trigger: 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.
Common situations: Building the parameter list dynamically from variables/config where one value is null; passing an uninitialized array; LINQ projections producing null entries.
Related errors
- Value cannot be null. (Parameter 'folderSecurity')
- Value cannot be null. Parameter name: path
- A maximum of 32 actions is allowed within a single task.
- Attachments array cannot contain more than 8 items.
- Each value of the array must contain a valid file reference.
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/89918cae00e5107d.
Report an issue: GitHub.