peass-ng/PEASS-ng · error · ArgumentNullException
Value cannot be null. Parameter name: path
Error message
Value cannot be null. Parameter name: path
What it means
EnableDisableEncryptionCore throws ArgumentNullException("path") when the path parameter is null, empty, or whitespace (Utils.IsNullOrWhiteSpace check). Directory.EnableEncryption / DisableEncryption need a concrete directory path to pass to EncryptionDisable, so an empty value is rejected immediately as a caller error.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.EnableDisableEncryptionCore.cs:49
/// <summary>Enables/disables encryption of the specified directory and the files in it.
/// <para>This method only creates/modifies the file "Desktop.ini" in the root of <paramref name="path"/> and enables/disables encryption by writing: "Disable=0" or "Disable=1".</para>
/// <para>This method does not affect encryption of files and subdirectories below the indicated directory.</para>
/// </summary>
/// <exception cref="ArgumentException"/>
/// <exception cref="ArgumentNullException"/>
/// <exception cref="DirectoryReadOnlyException"/>
/// <exception cref="FileReadOnlyException"/>
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="path">The name of the directory for which to enable encryption.</param>
/// <param name="enable"><c>true</c> enabled encryption, <c>false</c> disables encryption.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static void EnableDisableEncryptionCore(string path, bool enable, PathFormat pathFormat)
{
if (Utils.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");
var pathLp = Path.GetExtendedLengthPathCore(null, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);
// EncryptionDisable()
// 2013-01-13: MSDN does not confirm LongPath usage and no Unicode version of this function exists.
var success = NativeMethods.EncryptionDisable(pathLp, !enable);
var lastError = Marshal.GetLastWin32Error();
if (!success)
NativeError.ThrowException(lastError, true, pathLp);
}
}
}
View on GitHub (pinned to 53fb989abc)
Solutions
- Validate with string.IsNullOrWhiteSpace before calling and raise a meaningful domain error.
- Supply a default/known directory when the configured value is missing.
- Fix the source of the empty path (config load, env var, argument parsing).
- Guard batch loops: skip entries whose resolved path is empty instead of passing them through.
Example fix
// before
Directory.EnableEncryption(folderPath, true); // folderPath may be ""
// after
if (string.IsNullOrWhiteSpace(folderPath))
throw new ArgumentException("Encrypted folder path is not configured");
Directory.EnableEncryption(folderPath, true); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Directory path is required for EFS operations", nameof(path)); Type guard
bool HasPath(string p) => !string.IsNullOrWhiteSpace(p);
Try / catch
try { Directory.EnableEncryption(path, enable); }
catch (ArgumentNullException ex) { logger.LogError(ex, "Encryption target path missing"); } Prevention
- Validate config-sourced directory paths before EFS calls
- Fail fast on missing settings instead of propagating empty strings
- Skip empty entries in batch encryption loops
- Use guard clauses in wrappers around AlphaFS encryption APIs
When it happens
Trigger: Calling Directory.EnableEncryption(path, true) or DisableEncryption(path, false) with null/string.Empty/whitespace path; upstream config or registry value missing; a Path.Combine result that came back null/empty because an argument was empty.
Common situations: EFS-related setup scripts where the folder setting was never configured; environment-specific config files missing a key; loop variables that are empty on the last iteration of a batch operation.
Related errors
- Value cannot be null. Parameter name: path
- The drive does not support NTFS encryption: [{0}]
- ERROR_FILE_READ_ONLY
- Function '{func}' in module {path} is imported from itself
- Variable '{var}' in module {path} is imported from itself
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/60f79278e658dfed.
Report an issue: GitHub.