{"record":{"id":"8fe8386fc433e1ca","repo":"peass-ng/PEASS-ng","slug":"specified-argument-was-out-of-the-range-of-valid-v-8fe838","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'name')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'name'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskCollection.cs","lineNumber":246,"sourceCode":"                throw new ArgumentOutOfRangeException(nameof(index));\n            }\n        }\n\n        /// <summary>Gets the named registered task from the collection.</summary>\n        /// <param name=\"name\">The name of the registered task to be retrieved.</param>\n        /// <returns>A <see cref=\"Task\"/> instance that contains the requested context.</returns>\n        public Task this[string name]\n        {\n            get\n            {\n                if (v2Coll != null)\n                    return Task.CreateTask(svc, v2Coll[name]);\n\n                var v1Task = svc.GetTask(name);\n                if (v1Task != null)\n                    return v1Task;\n\n                throw new ArgumentOutOfRangeException(nameof(name));\n            }\n        }\n\n        /// <summary>Releases all resources used by this class.</summary>\n        public void Dispose()\n        {\n            v1TS = null;\n            if (v2Coll != null)\n                Marshal.ReleaseComObject(v2Coll);\n        }\n\n        /// <summary>Determines whether the specified task exists.</summary>\n        /// <param name=\"taskName\">The name of the task.</param>\n        /// <returns>true if task exists; otherwise, false.</returns>\n        public bool Exists([NotNull] string taskName)\n        {\n            try\n            {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskCollection.cs#L228-L264","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify existence first by iterating Tasks and matching names case-insensitively","Ensure you are querying the correct TaskFolder (use TaskService.GetFolder(path) matching where the task is registered)","Register the task before accessing it (TaskFolder.RegisterTaskDefinition)","Catch ArgumentOutOfRangeException around name-based lookups and handle the missing-task case"],"exampleFix":"// before\nvar task = folder.Tasks[\"MyTask\"];\n// after\nvar task = folder.Tasks.Cast<Task>().FirstOrDefault(t => string.Equals(t.Name, \"MyTask\", StringComparison.OrdinalIgnoreCase));\nif (task == null) Log(\"Task not registered in this folder\");","handlingStrategy":"try-catch","validationCode":"bool exists = folder.Tasks.Cast<Task>().Any(t => string.Equals(t.Name, name, StringComparison.OrdinalIgnoreCase));","typeGuard":"bool TryGetTask(TaskFolder folder, string name, out Task task) { task = folder.Tasks.Cast<Task>().FirstOrDefault(t => t.Name == name); return task != null; }","tryCatchPattern":"try { task = folder.Tasks[name]; } catch (ArgumentOutOfRangeException) { Log($\"Task '{name}' not found in folder\"); task = null; }","preventionTips":["Confirm exact task name and folder path before lookup","Register the task before referencing it","Use case-insensitive matching and FirstOrDefault for resilient lookups"],"tags":["taskscheduler","argumentoutofrange","missing-task","name-lookup"],"backgroundTag":"collection-key-not-found","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}