peass-ng/PEASS-ng · error · System.ArgumentException

Each value of the array must contain a valid file reference.

Error message

Each value of the array must contain a valid file reference.

What it means

When validateAttachments is enabled, each entry of the Attachments array must be a string containing an existing file path. Any non-string element or path for which System.IO.File.Exists returns false throws ArgumentException. This is an upfront validation so failures surface at assignment rather than at task registration/runtime.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs:461

            /// 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>
            [DefaultValue(null)]
            public string Bcc
            {
                get => GetProperty<string, IEmailAction>(nameof(Bcc));
                set => SetProperty<string, IEmailAction>(nameof(Bcc), value);

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Expand environment variables and resolve to absolute paths before assigning (Environment.ExpandEnvironmentVariables, Path.GetFullPath)
  2. Filter the array with File.Exists before setting the property
  3. Ensure validateAttachments expectations are met or disable validation only if you accept runtime failures
  4. Catch ArgumentException and report which entry failed

Example fix

// before
emailAction.Attachments = rawPaths;
// after
var ok = rawPaths.Select(p => Environment.ExpandEnvironmentVariables(p))
                 .Where(p => File.Exists(p)).Cast<object>().ToArray();
emailAction.Attachments = ok;
Defensive patterns

Strategy: validation

Validate before calling

static string[] ResolveExistingAttachments(IEnumerable<string> paths) =>
    paths.Select(p => Environment.ExpandEnvironmentVariables(p))
         .Select(Path.GetFullPath)
         .Where(File.Exists)
         .ToArray();

Try / catch

try { emailAction.Attachments = resolved; }
catch (ArgumentException ex)
{
    log.Error($"Attachment validation failed: {ex.Message}");
}

Prevention

When it happens

Trigger: Assigning Attachments containing null entries, non-string objects, relative paths that do not resolve from the current directory, UNC paths not reachable, or files deleted between config load and assignment.

Common situations: Task XML/config with placeholder paths; attachments referencing per-user paths (e.g. %USERPROFILE%) that were never expanded; network shares unavailable when the process runs under another account; typos in paths.

Related errors


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