{"record":{"id":"c1c0eac677ee5e1c","repo":"peass-ng/PEASS-ng","slug":"specified-argument-was-out-of-the-range-of-valid-v","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'index')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'index'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskCollection.cs","lineNumber":62,"sourceCode":"        /// <summary>Gets the specified running task from the collection.</summary>\n        /// <param name=\"index\">The index of the running task to be retrieved.</param>\n        /// <returns>A <see cref=\"RunningTask\"/> instance.</returns>\n        public RunningTask this[int index]\n        {\n            get\n            {\n                if (v2Coll != null)\n                {\n                    var irt = v2Coll[++index];\n                    return new RunningTask(svc, TaskService.GetTask(svc.v2TaskService, irt.Path), irt);\n                }\n\n                var i = 0;\n                var v1Enum = new V1RunningTaskEnumerator(svc);\n                while (v1Enum.MoveNext())\n                    if (i++ == index)\n                        return v1Enum.Current;\n                throw new ArgumentOutOfRangeException(nameof(index));\n            }\n        }\n\n        /// <summary>Releases all resources used by this class.</summary>\n        public void Dispose()\n        {\n            if (v2Coll != null)\n                Marshal.ReleaseComObject(v2Coll);\n        }\n\n        /// <summary>Gets an IEnumerator instance for this collection.</summary>\n        /// <returns>An enumerator.</returns>\n        public IEnumerator<RunningTask> GetEnumerator()\n        {\n            if (v2Coll != null)\n                return new ComEnumerator<RunningTask, IRunningTask>(() => v2Coll.Count, (object o) => v2Coll[o], o =>\n                {\n                    IRegisteredTask task = null;","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskCollection.cs#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"Iterating a running-task list with a cached/stale count; racing with tasks completing; assuming the running set matches the registered-task set.","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"],"exampleFix":"// before\nvar task = runningTasks[i];\n// after\nvar task = runningTasks.FirstOrDefault(t => /* match criteria */);\n// or: foreach (var t in runningTasks) { ... }","handlingStrategy":"try-catch","validationCode":"if (index >= 0 && index < runningTasks.Count) { var t = runningTasks[index]; }","typeGuard":null,"tryCatchPattern":"try { var t = runningTasks[i]; } catch (ArgumentOutOfRangeException) { Log(\"Running task no longer active\"); }","preventionTips":["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"],"tags":["taskscheduler","argumentoutofrange","indexer","collection"],"backgroundTag":"index-out-of-range","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}