{"record":{"id":"404a4736e822307a","repo":"peass-ng/PEASS-ng","slug":"each-value-of-the-array-must-contain-a-valid-file","errorCode":null,"errorMessage":"Each value of the array must contain a valid file reference.","messagePattern":"Each value of the array must contain a valid file reference\\.","errorType":"exception","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs","lineNumber":461,"sourceCode":"            /// 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>\n            [DefaultValue(null)]\n            public string Bcc\n            {\n                get => GetProperty<string, IEmailAction>(nameof(Bcc));\n                set => SetProperty<string, IEmailAction>(nameof(Bcc), value);","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs#L443-L479","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Expand environment variables and resolve to absolute paths before assigning (Environment.ExpandEnvironmentVariables, Path.GetFullPath)","Filter the array with File.Exists before setting the property","Ensure validateAttachments expectations are met or disable validation only if you accept runtime failures","Catch ArgumentException and report which entry failed"],"exampleFix":"// before\nemailAction.Attachments = rawPaths;\n// after\nvar ok = rawPaths.Select(p => Environment.ExpandEnvironmentVariables(p))\n                 .Where(p => File.Exists(p)).Cast<object>().ToArray();\nemailAction.Attachments = ok;","handlingStrategy":"validation","validationCode":"static string[] ResolveExistingAttachments(IEnumerable<string> paths) =>\n    paths.Select(p => Environment.ExpandEnvironmentVariables(p))\n         .Select(Path.GetFullPath)\n         .Where(File.Exists)\n         .ToArray();","typeGuard":null,"tryCatchPattern":"try { emailAction.Attachments = resolved; }\ncatch (ArgumentException ex)\n{\n    log.Error($\"Attachment validation failed: {ex.Message}\");\n}","preventionTips":["Expand environment variables and make paths absolute before assigning","Filter with File.Exists at assignment time (and remember existence can change later)","Avoid per-user paths in machine-wide task definitions","Ensure the task's runtime account can reach network-share attachments"],"tags":["csharp","taskscheduler","email","file-validation"],"backgroundTag":"attachment-file-not-found","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}