peass-ng/PEASS-ng · error · System.ArgumentOutOfRangeException
Index is not a valid index in the ActionCollection
Error message
Index is not a valid index in the ActionCollection
What it means
The ActionCollection indexer setter validates that the index refers to an existing action; if index is negative or >= Count it throws ArgumentOutOfRangeException with this message. This protects the underlying COM collection (v2) and the internal v1 action list from out-of-range writes.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/ActionCollection.cs:249
{
if (v2Coll != null)
return Action.CreateAction(v2Coll[++index]);
if (v1Task != null)
{
if (SupportV1Conversion)
return v1Actions[index];
else
{
if (index == 0)
return v1Actions[0];
}
}
throw new ArgumentOutOfRangeException();
}
set
{
if (index < 0 || Count <= index)
throw new ArgumentOutOfRangeException(nameof(index), index, "Index is not a valid index in the ActionCollection");
var orig = this[index].Clone();
if (v2Coll != null)
{
inV2set = true;
try
{
Insert(index, value);
RemoveAt(index + 1);
}
finally
{
inV2set = false;
}
}
else
{
v1Actions[index] = value;
SaveV1Actions();View on GitHub (pinned to 53fb989abc)
Solutions
- Use Actions.Add(newAction) instead of the indexer to append new actions
- Re-check Count immediately before each indexed write; iterate with for (int i = 0; i < actions.Count; i++)
- If replacing, capture a fresh index from IndexOf rather than a cached value
- Catch ArgumentOutOfRangeException and treat as a logic bug — log collection state for diagnosis
Example fix
// before
int saved = actions.Count;
// ... other code removes actions ...
actions[saved] = new ExecAction("cmd.exe"); // out of range
// after
actions.Add(new ExecAction("cmd.exe")); // append via Add
// or, for replace:
int idx = actions.IndexOf(existing);
if (idx >= 0 && idx < actions.Count) actions[idx] = new ExecAction("cmd.exe"); Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidActionIndex(ActionCollection actions, int i) => i >= 0 && i < actions.Count;
Try / catch
try { actions[index] = newAction; }
catch (ArgumentOutOfRangeException ex)
{
log.Error($"Action index {index} invalid (Count={actions.Count}); use Add to append.");
} Prevention
- Use Add for appending — the indexer only replaces existing items
- Re-read Count right before indexed writes; never cache indices across modifications
- Iterate with for loops bounded by the live Count
- Fetch indices via IndexOf instead of remembering old positions
When it happens
Trigger: Assigning actions[Count] to 'append' (the setter does not append — use Add); looping with an upper bound from a stale count captured before removals; passing a saved index after the collection was modified.
Common situations: Code that assumes list-style append-by-index semantics; UI list updates after actions were deleted elsewhere; deserialization logic writing items at their original indices into a shorter collection.
Related errors
- 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.
- Under Windows 8 and later, EmailAction objects are converted
- Only a single {nameof(Action.ExecAction)} is supported unles
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/0ed3b78003b057e0.
Report an issue: GitHub.