peass-ng/PEASS-ng · error · ArgumentNullException

Value cannot be null. Parameter name: sourcePath

Error message

Value cannot be null.
Parameter name: sourcePath

What it means

File.Move / CopyMove argument validation requires a non-null sourcePath. When the PathFormat is not LongFullPath (so the path must be validated/normalized), a null sourcePath causes ArgumentNullException("sourcePath").

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File CopyMove/File.ValidateFileOrDirectoryMoveArguments.cs:57

      private static CopyMoveArguments ValidateFileOrDirectoryMoveArguments(CopyMoveArguments cma, bool driveChecked, bool isFolder, string sourcePath, string destinationPath, out string sourcePathLp, out string destinationPathLp)
      {
         sourcePathLp = sourcePath;
         destinationPathLp = destinationPath;
         
         if (cma.PathsChecked)
            return cma;


         cma.IsCopy = IsCopyAction(cma);

         if (!cma.IsCopy)
            cma.DelayUntilReboot = VerifyDelayUntilReboot(sourcePath, cma.MoveOptions, cma.PathFormat);


         if (cma.PathFormat != PathFormat.LongFullPath)
         {
            if (null == sourcePath)
               throw new ArgumentNullException("sourcePath");
            
            // File Move action: destinationPath is allowed to be null when MoveOptions.DelayUntilReboot is specified.

            if (!cma.DelayUntilReboot && null == destinationPath)
               throw new ArgumentNullException("destinationPath");
            

            if (sourcePath.Trim().Length == 0)
               throw new ArgumentException(Resources.Path_Is_Zero_Length_Or_Only_White_Space, "sourcePath");

            if (null != destinationPath && destinationPath.Trim().Length == 0)
               throw new ArgumentException(Resources.Path_Is_Zero_Length_Or_Only_White_Space, "destinationPath");


            // MSDN: .NET3.5+: IOException: The sourceDirName and destDirName parameters refer to the same file or directory.
            // Do not use StringComparison.OrdinalIgnoreCase to allow renaming a folder with different casing.

            if (sourcePath.Equals(destinationPath, StringComparison.Ordinal))

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a valid, non-null source path string.
  2. Check the source value for null before calling and fail early with a meaningful message.
  3. Guard config/CLI-derived values with string.IsNullOrEmpty before invoking the move.

Example fix

// before
File.Move(srcPath, dstPath); // ArgumentNullException if srcPath is null
// after
if (string.IsNullOrEmpty(srcPath))
    throw new ArgumentException("Source path is required.", nameof(srcPath));
File.Move(srcPath, dstPath);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(sourcePath))
    throw new ArgumentException("sourcePath must be a non-empty path.", nameof(sourcePath));
// then call File.Move(sourcePath, destinationPath);

Type guard

static bool IsValidSourcePath(string p) => !string.IsNullOrWhiteSpace(p);

Try / catch

try { File.Move(sourcePath, destinationPath); }
catch (ArgumentNullException ex) when (ex.ParamName == "sourcePath")
{
    // source never resolved; report/log the configuration problem
    throw new InvalidOperationException("Source path was not provided.", ex);
}

Prevention

When it happens

Trigger: Calling File.Move(null, dst) or File.CopyMove(null, dst, ...) with a non-LongFullPath PathFormat. Note destinationPath may be null only when MoveOptions.DelayUntilReboot is set; sourcePath may never be null.

Common situations: Building paths from variables that failed to resolve (config value, registry value, or command-line argument left null); passing the result of a lookup that returned null.

Related errors


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