{"record":{"id":"0b50972c9483673f","repo":"peass-ng/PEASS-ng","slug":"value-cannot-be-null-parameter-foldersecurity","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'folderSecurity')","messagePattern":"Value cannot be null\\. \\(Parameter 'folderSecurity'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolder.cs","lineNumber":167,"sourceCode":"        /// <summary>\n        /// Creates a folder for related tasks. Not available to Task Scheduler 1.0.\n        /// </summary>\n        /// <param name=\"subFolderName\">The name used to identify the folder. If \"FolderName\\SubFolder1\\SubFolder2\" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see cref=\"TaskFolder\"/> instance. The root task folder is specified with a backslash (\\). An example of a task folder path, under the root task folder, is \\MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>\n        /// <param name=\"sd\">The security descriptor associated with the folder.</param>\n        /// <returns>A <see cref=\"TaskFolder\"/> instance that represents the new subfolder.</returns>\n        [Obsolete(\"This method will be removed in deference to the CreateFolder(string, TaskSecurity) method.\")]\n        public TaskFolder CreateFolder([NotNull] string subFolderName, GenericSecurityDescriptor sd) => CreateFolder(subFolderName, sd == null ? null : sd.GetSddlForm(Task.defaultAccessControlSections));\n\n        /// <summary>\n        /// Creates a folder for related tasks. Not available to Task Scheduler 1.0.\n        /// </summary>\n        /// <param name=\"subFolderName\">The name used to identify the folder. If \"FolderName\\SubFolder1\\SubFolder2\" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see cref=\"TaskFolder\"/> instance. The root task folder is specified with a backslash (\\). An example of a task folder path, under the root task folder, is \\MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>\n        /// <param name=\"folderSecurity\">The task security associated with the folder.</param>\n        /// <returns>A <see cref=\"TaskFolder\"/> instance that represents the new subfolder.</returns>\n        public TaskFolder CreateFolder([NotNull] string subFolderName, [NotNull] TaskSecurity folderSecurity)\n        {\n            if (folderSecurity == null)\n                throw new ArgumentNullException(nameof(folderSecurity));\n            return CreateFolder(subFolderName, folderSecurity.GetSecurityDescriptorSddlForm(Task.defaultAccessControlSections));\n        }\n\n        /// <summary>\n        /// Creates a folder for related tasks. Not available to Task Scheduler 1.0.\n        /// </summary>\n        /// <param name=\"subFolderName\">The name used to identify the folder. If \"FolderName\\SubFolder1\\SubFolder2\" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see cref=\"TaskFolder\" /> instance. The root task folder is specified with a backslash (\\). An example of a task folder path, under the root task folder, is \\MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>\n        /// <param name=\"sddlForm\">The security descriptor associated with the folder.</param>\n        /// <param name=\"exceptionOnExists\">Set this value to false to avoid having an exception called if the folder already exists.</param>\n        /// <returns>A <see cref=\"TaskFolder\" /> instance that represents the new subfolder.</returns>\n        /// <exception cref=\"System.Security.SecurityException\">Security descriptor mismatch between specified credentials and credentials on existing folder by same name.</exception>\n        /// <exception cref=\"System.ArgumentException\">Invalid SDDL form.</exception>\n        /// <exception cref=\"Microsoft.Win32.TaskScheduler.NotV1SupportedException\">Not supported under Task Scheduler 1.0.</exception>\n        public TaskFolder CreateFolder([NotNull] string subFolderName, string sddlForm = null, bool exceptionOnExists = true)\n        {\n            if (v2Folder == null) throw new NotV1SupportedException();\n            ITaskFolder ifld = null;\n            try { ifld = v2Folder.CreateFolder(subFolderName, sddlForm); }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolder.cs#L149-L185","documentation":"TaskFolder.CreateFolder(string, TaskSecurity) is annotated [NotNull] for folderSecurity and explicitly throws ArgumentNullException when it is null. The security descriptor is required to derive the SDDL string passed to the underlying COM CreateFolder call.","triggerScenarios":"Calling CreateFolder(\"name\", null) with the TaskSecurity overload — the null check runs before GetSecurityDescriptorSddlForm is invoked.","commonSituations":"Developer omits the security parameter thinking it's optional; refactoring code that previously used the string-sddl overload; passing a variable that failed to initialize.","solutions":["Pass a valid TaskSecurity instance, e.g. new TaskSecurity(), or default folder security","Use the overload CreateFolder(string, string sddlForm, bool) if default security is desired","Add a null check on the TaskSecurity argument at the call site"],"exampleFix":"// before\nrootFolder.CreateFolder(\"MyFolder\", null);\n// after\nvar security = new TaskSecurity();\nrootFolder.CreateFolder(\"MyFolder\", security);","handlingStrategy":"validation","validationCode":"if (folderSecurity == null) folderSecurity = new TaskSecurity();","typeGuard":null,"tryCatchPattern":"try { folder.CreateFolder(name, sec); }\ncatch (ArgumentNullException) { /* supply a TaskSecurity */ }","preventionTips":["Always construct a TaskSecurity before calling the security-based overload","Prefer the sddlForm overload with default null when default security is fine","Enable nullable reference types to catch missing arguments at compile time"],"tags":["argumentnull","taskscheduler","folders","validation"],"backgroundTag":"null-argument","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}