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
- Pass a valid, non-null source path string.
- Check the source value for null before calling and fail early with a meaningful message.
- 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
- Validate all path inputs with string.IsNullOrWhiteSpace before filesystem calls
- Fail fast when config/env/CLI values that supply paths are null
- Never pass null for sourcePath even when using DelayUntilReboot (only destination may be null)
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
- Value cannot be null. Parameter name: destinationPath
- Invalid Subpath
- Cannot determine Copy or Move action.
- Path is a zero-length string or contains only white space.
- MoveOptions.CopyAllowed is not allowed when using the MoveOp
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/2063727f5b51fdcb.
Report an issue: GitHub.