{"record":{"id":"6431d2cff9aa85a3","repo":"peass-ng/PEASS-ng","slug":"attachments-array-cannot-contain-more-than-8-items","errorCode":null,"errorMessage":"Attachments array cannot contain more than 8 items.","messagePattern":"Attachments array cannot contain more than 8 items\\.","errorType":"exception","errorClass":"System.ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs","lineNumber":456,"sourceCode":"            {\n            }\n\n            /// <summary>\n            /// Gets or sets an array of file paths to be sent as attachments with the e-mail. Each item must be a <see cref=\"string\"/> value\n            /// containing a path to file.\n            /// </summary>\n            [XmlArray(\"Attachments\", IsNullable = true)]\n            [XmlArrayItem(\"File\", typeof(string))]\n            [DefaultValue(null)]\n            public object[] Attachments\n            {\n                get => GetProperty<object[], IEmailAction>(nameof(Attachments));\n                set\n                {\n                    if (value != null)\n                    {\n                        if (value.Length > 8)\n                            throw new ArgumentOutOfRangeException(nameof(Attachments), @\"Attachments array cannot contain more than 8 items.\");\n                        if (validateAttachments)\n                        {\n                            foreach (var o in value)\n                                if (!(o is string) || !System.IO.File.Exists((string)o))\n                                    throw new ArgumentException(@\"Each value of the array must contain a valid file reference.\", nameof(Attachments));\n                        }\n                    }\n                    if (iAction == null && (value == null || value.Length == 0))\n                    {\n                        unboundValues.Remove(nameof(Attachments));\n                        OnPropertyChanged(nameof(Attachments));\n                    }\n                    else\n                        SetProperty<object[], IEmailAction>(nameof(Attachments), value);\n                }\n            }\n\n            /// <summary>Gets or sets the e-mail address or addresses that you want to Bcc in the e-mail.</summary>","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs#L438-L474","documentation":"EmailAction.Attachments models the underlying IEmailAction attachments list, which Windows Task Scheduler caps at 8 items. Setting more than 8 throws ArgumentOutOfRangeException before the value reaches COM. The cap mirrors the native Task Scheduler restriction (V1 8-item cap enforced by the library).","triggerScenarios":"Assigning an object[]/string[] with 9+ file paths to the Attachments property, either directly or via constructor/config loading of an email action.","commonSituations":"Bulk-report tasks attaching many log files; generated alerts attaching all files in a directory; importing older task XML with a large attachment list.","solutions":["Limit the Attachments array to 8 entries; attach remaining files via a zip archive or a link instead","Validate the array length before assigning and split into multiple email actions if needed","Zip the files and attach the single archive when more than 8 files must be sent","Catch ArgumentOutOfRangeException around the property set to give a user-friendly message"],"exampleFix":"// before\nemailAction.Attachments = allLogFiles; // may exceed 8\n// after\nemailAction.Attachments = allLogFiles.Take(8).ToArray();","handlingStrategy":"validation","validationCode":"static bool AttachmentsWithinLimit(object[] a) => a == null || a.Length <= 8;","typeGuard":null,"tryCatchPattern":"try { emailAction.Attachments = files; }\ncatch (ArgumentOutOfRangeException)\n{\n    log.Error(\"Email action supports at most 8 attachments; zip files or split the alert.\");\n}","preventionTips":["Truncate or chunk attachment lists to 8 items max","Zip many files into one archive and attach that","Validate array length before assignment, not at registration time","Split high-volume notifications into multiple email actions"],"tags":["csharp","taskscheduler","email","limit-exceeded"],"backgroundTag":"attachment-limit-exceeded","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}