peass-ng/PEASS-ng · error · System.ArgumentOutOfRangeException
Attachments array cannot contain more than 8 items.
Error message
Attachments array cannot contain more than 8 items.
What it means
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).
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs:456
{
}
/// <summary>
/// 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
/// containing a path to file.
/// </summary>
[XmlArray("Attachments", IsNullable = true)]
[XmlArrayItem("File", typeof(string))]
[DefaultValue(null)]
public object[] Attachments
{
get => GetProperty<object[], IEmailAction>(nameof(Attachments));
set
{
if (value != null)
{
if (value.Length > 8)
throw new ArgumentOutOfRangeException(nameof(Attachments), @"Attachments array cannot contain more than 8 items.");
if (validateAttachments)
{
foreach (var o in value)
if (!(o is string) || !System.IO.File.Exists((string)o))
throw new ArgumentException(@"Each value of the array must contain a valid file reference.", nameof(Attachments));
}
}
if (iAction == null && (value == null || value.Length == 0))
{
unboundValues.Remove(nameof(Attachments));
OnPropertyChanged(nameof(Attachments));
}
else
SetProperty<object[], IEmailAction>(nameof(Attachments), value);
}
}
/// <summary>Gets or sets the e-mail address or addresses that you want to Bcc in the e-mail.</summary>View on GitHub (pinned to 53fb989abc)
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
Example fix
// before emailAction.Attachments = allLogFiles; // may exceed 8 // after emailAction.Attachments = allLogFiles.Take(8).ToArray();
Defensive patterns
Strategy: validation
Validate before calling
static bool AttachmentsWithinLimit(object[] a) => a == null || a.Length <= 8;
Try / catch
try { emailAction.Attachments = files; }
catch (ArgumentOutOfRangeException)
{
log.Error("Email action supports at most 8 attachments; zip files or split the alert.");
} Prevention
- 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
When it happens
Trigger: Assigning an object[]/string[] with 9+ file paths to the Attachments property, either directly or via constructor/config loading of an email action.
Common situations: Bulk-report tasks attaching many log files; generated alerts attaching all files in a directory; importing older task XML with a large attachment list.
Related errors
- A maximum of 32 actions is allowed within a single task.
- Each value of the array must contain a valid file reference.
- Under Windows 8 and later, EmailAction objects are converted
- Index is not a valid index in the ActionCollection
- 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/6431d2cff9aa85a3.
Report an issue: GitHub.