peass-ng/PEASS-ng · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values. (Pa
Error message
Specified argument was out of the range of valid values. (Parameter 'index')
What it means
RunningTaskCollection's indexer walks the V1 running-task enumerator and throws ArgumentOutOfRangeException("index") when the supplied index exceeds the number of currently running tasks. Under the V1 API the collection length is unknown upfront, so out-of-range access is only detected during enumeration.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskCollection.cs:62
/// <summary>Gets the specified running task from the collection.</summary>
/// <param name="index">The index of the running task to be retrieved.</param>
/// <returns>A <see cref="RunningTask"/> instance.</returns>
public RunningTask this[int index]
{
get
{
if (v2Coll != null)
{
var irt = v2Coll[++index];
return new RunningTask(svc, TaskService.GetTask(svc.v2TaskService, irt.Path), irt);
}
var i = 0;
var v1Enum = new V1RunningTaskEnumerator(svc);
while (v1Enum.MoveNext())
if (i++ == index)
return v1Enum.Current;
throw new ArgumentOutOfRangeException(nameof(index));
}
}
/// <summary>Releases all resources used by this class.</summary>
public void Dispose()
{
if (v2Coll != null)
Marshal.ReleaseComObject(v2Coll);
}
/// <summary>Gets an IEnumerator instance for this collection.</summary>
/// <returns>An enumerator.</returns>
public IEnumerator<RunningTask> GetEnumerator()
{
if (v2Coll != null)
return new ComEnumerator<RunningTask, IRunningTask>(() => v2Coll.Count, (object o) => v2Coll[o], o =>
{
IRegisteredTask task = null;View on GitHub (pinned to 53fb989abc)
Solutions
- Enumerate the collection with foreach instead of indexing
- Compare against the live Count immediately before indexing, or use FirstOrDefault-style iteration
- Re-fetch the collection after any wait/state change rather than reusing a stale reference
- Catch ArgumentOutOfRangeException when the index is derived from external input
Example fix
// before
var task = runningTasks[i];
// after
var task = runningTasks.FirstOrDefault(t => /* match criteria */);
// or: foreach (var t in runningTasks) { ... } Defensive patterns
Strategy: try-catch
Validate before calling
if (index >= 0 && index < runningTasks.Count) { var t = runningTasks[index]; } Try / catch
try { var t = runningTasks[i]; } catch (ArgumentOutOfRangeException) { Log("Running task no longer active"); } Prevention
- Prefer foreach enumeration over positional indexing
- Never cache counts across waits; the running set changes constantly
- Validate external indexes against live Count immediately before use
When it happens
Trigger: Accessing RunningTaskCollection[index] where index >= the number of tasks currently running (V1 path at TaskCollection.cs:62), e.g. collection[5] when only 2 tasks are running; also when a task finishes between a Count check and the indexer call.
Common situations: Iterating a running-task list with a cached/stale count; racing with tasks completing; assuming the running set matches the registered-task set.
Related errors
- Index is not a valid index in the ActionCollection
- On systems prior to Windows 10, all individual parameters mu
- A maximum of 32 parameters can be supplied to RunEx.
- On systems prior to Windows 10, no individual parameter may
- Specified argument was out of the range of valid values. (Pa
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/c1c0eac677ee5e1c.
Report an issue: GitHub.