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

DeleteDirectoryCore throws ArgumentNullException("path") when both the fsEntryInfo parameter and the path parameter are null. The method needs at least one way to identify the directory to delete: if fsEntryInfo is not supplied, it resolves fsEntryInfo from path via GetFileSystemEntryInfoCore, so a null path with null fsEntryInfo is unrecoverable. This is a caller programming error, not an OS error.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.DeleteDirectoryCore.cs:54

      /// <exception cref="DirectoryNotFoundException"/>
      /// <exception cref="IOException"/>
      /// <exception cref="NotSupportedException"/>
      /// <exception cref="UnauthorizedAccessException"/>
      /// <exception cref="DirectoryReadOnlyException"/>
      /// <param name="transaction">The transaction.</param>
      /// <param name="fsEntryInfo">A FileSystemEntryInfo instance. Use either <paramref name="fsEntryInfo"/> or <paramref name="path"/>, not both.</param>
      /// <param name="path">The name of the directory to remove. Use either <paramref name="path"/> or <paramref name="fsEntryInfo"/>, not both.</param>
      /// <param name="recursive"><c>true</c> to remove all files and subdirectories recursively; <c>false</c> otherwise only the top level empty directory.</param>
      /// <param name="ignoreReadOnly"><c>true</c> overrides read only attribute of files and directories.</param>
      /// <param name="continueOnNotFound">When <c>true</c> does not throw an <see cref="DirectoryNotFoundException"/> when the directory does not exist.</param>
      /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
      [SecurityCritical]
      internal static void DeleteDirectoryCore(KernelTransaction transaction, FileSystemEntryInfo fsEntryInfo, string path, bool recursive, bool ignoreReadOnly, bool continueOnNotFound, PathFormat pathFormat)
      {
         if (null == fsEntryInfo)
         {
            if (null == path)
               throw new ArgumentNullException("path");
            
            fsEntryInfo = File.GetFileSystemEntryInfoCore(transaction, true, Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator), continueOnNotFound, pathFormat);

            if (null == fsEntryInfo)
               return;
         }


         PrepareDirectoryForDelete(transaction, fsEntryInfo, ignoreReadOnly);


         // Do not follow mount points nor symbolic links, but do delete the reparse point itself.
         // If directory is reparse point, disable recursion.

         if (recursive && !fsEntryInfo.IsReparsePoint)
         {
            // The stack will contain the entire folder structure to prevent any open directory handles because of enumeration.
            // The root folder is at the bottom of the stack.

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Validate the path with string.IsNullOrWhiteSpace before calling Delete and fail fast with your own error.
  2. Ensure upstream path-building code (Path.Combine, config reads) cannot yield null.
  3. Pass a valid FileSystemEntryInfo obtained from File.GetFileSystemEntryInfo if you prefer object-based deletion.
  4. Catch ArgumentNullException at the boundary to convert it into a user-facing 'directory not specified' message.

Example fix

// before
Directory.Delete(configuredPath, true); // configuredPath may be null
// after
if (string.IsNullOrWhiteSpace(configuredPath))
    throw new InvalidOperationException("No directory configured for deletion");
Directory.Delete(configuredPath, true);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(path))
    throw new ArgumentException("A directory path is required", nameof(path));

Type guard

bool HasPath(string p) => !string.IsNullOrWhiteSpace(p);

Try / catch

try { Directory.Delete(path, recursive); }
catch (ArgumentNullException ex) { logger.LogError(ex, "Delete called without a path"); }

Prevention

When it happens

Trigger: Passing null for path (and null fsEntryInfo) to Directory.Delete or any of its wrappers that route through DeleteDirectoryCore (CopyMoveCore, CopyMoveDirectoryCore, CreateJunctionCore, DeleteEmptySubdirectoriesCore, DeleteJunctionCore). Typically the result of an uninitialized or failed path-computation upstream (e.g. Path.Combine returned null via a null argument).

Common situations: A configuration value or command-line argument for the directory was missing; a lookup that should produce a path returned null and was passed straight to Delete; deserialization left a path property null.

Related errors


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