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 'name')

What it means

TaskCollection's name indexer returns the registered task with the given name; if the V2 collection doesn't contain it and the V1 service lookup returns null, it throws ArgumentOutOfRangeException("name") at TaskCollection.cs:246. Despite the unusual exception type, it effectively means 'no task registered with that name in this folder'.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskCollection.cs:246

                throw new ArgumentOutOfRangeException(nameof(index));
            }
        }

        /// <summary>Gets the named registered task from the collection.</summary>
        /// <param name="name">The name of the registered task to be retrieved.</param>
        /// <returns>A <see cref="Task"/> instance that contains the requested context.</returns>
        public Task this[string name]
        {
            get
            {
                if (v2Coll != null)
                    return Task.CreateTask(svc, v2Coll[name]);

                var v1Task = svc.GetTask(name);
                if (v1Task != null)
                    return v1Task;

                throw new ArgumentOutOfRangeException(nameof(name));
            }
        }

        /// <summary>Releases all resources used by this class.</summary>
        public void Dispose()
        {
            v1TS = null;
            if (v2Coll != null)
                Marshal.ReleaseComObject(v2Coll);
        }

        /// <summary>Determines whether the specified task exists.</summary>
        /// <param name="taskName">The name of the task.</param>
        /// <returns>true if task exists; otherwise, false.</returns>
        public bool Exists([NotNull] string taskName)
        {
            try
            {

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Verify existence first by iterating Tasks and matching names case-insensitively
  2. Ensure you are querying the correct TaskFolder (use TaskService.GetFolder(path) matching where the task is registered)
  3. Register the task before accessing it (TaskFolder.RegisterTaskDefinition)
  4. Catch ArgumentOutOfRangeException around name-based lookups and handle the missing-task case

Example fix

// before
var task = folder.Tasks["MyTask"];
// after
var task = folder.Tasks.Cast<Task>().FirstOrDefault(t => string.Equals(t.Name, "MyTask", StringComparison.OrdinalIgnoreCase));
if (task == null) Log("Task not registered in this folder");
Defensive patterns

Strategy: try-catch

Validate before calling

bool exists = folder.Tasks.Cast<Task>().Any(t => string.Equals(t.Name, name, StringComparison.OrdinalIgnoreCase));

Type guard

bool TryGetTask(TaskFolder folder, string name, out Task task) { task = folder.Tasks.Cast<Task>().FirstOrDefault(t => t.Name == name); return task != null; }

Try / catch

try { task = folder.Tasks[name]; } catch (ArgumentOutOfRangeException) { Log($"Task '{name}' not found in folder"); task = null; }

Prevention

When it happens

Trigger: Accessing taskFolder.Tasks["SomeName"] where no task of that exact name exists in the folder; name casing/prefix mismatches; querying a task that was deleted or exists in a different folder path.

Common situations: Hard-coded task names that were renamed; deploying to a machine where the task was never registered; looking up a task by path in the root folder instead of its subfolder; case-sensitivity assumptions.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/8fe8386fc433e1ca. Report an issue: GitHub.