peass-ng/PEASS-ng · error · ArgumentNullException

drivePath

Error message

drivePath

What it means

AlphaFS's DiskSpaceInfo constructor throws ArgumentNullException with param name 'drivePath' when the passed drive path is null, empty, or whitespace. AlphaFS validates inputs eagerly so drive queries fail clearly rather than deep inside Win32 calls.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DiskSpaceInfo.cs:53

   [Serializable]
   [SecurityCritical]
   public sealed class DiskSpaceInfo
   {
      [NonSerialized] private readonly bool _initGetClusterInfo = true;
      [NonSerialized] private readonly bool _initGetSpaceInfo = true;
      [NonSerialized] private readonly CultureInfo _cultureInfo = CultureInfo.CurrentCulture;
      [NonSerialized] private readonly bool _continueOnAccessError;


      /// <summary>Initializes a DiskSpaceInfo instance.</summary>
      /// <param name="drivePath">A valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z' or a network share in the format: \\server\share</param>
      /// <Remark>This is a Lazyloading object; call <see cref="Refresh()"/> to populate all properties first before accessing.</Remark>
      [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
      [SecurityCritical]
      public DiskSpaceInfo(string drivePath)
      {
         if (Utils.IsNullOrWhiteSpace(drivePath))
            throw new ArgumentNullException("drivePath");


         drivePath = drivePath.Length == 1 ? drivePath + Path.VolumeSeparatorChar : Path.GetPathRoot(drivePath, false);

         if (Utils.IsNullOrWhiteSpace(drivePath))
            throw new ArgumentException(Resources.InvalidDriveLetterArgument, "drivePath");


         // MSDN:
         // If this parameter is a UNC name, it must include a trailing backslash (for example, "\\MyServer\MyShare\").
         // Furthermore, a drive specification must have a trailing backslash (for example, "C:\").
         // The calling application must have FILE_LIST_DIRECTORY access rights for this directory.
         DriveName = Path.AddTrailingDirectorySeparator(drivePath, false);
      }

      
      /// <summary>Initializes a DiskSpaceInfo instance.</summary>
      /// <param name="drivePath">A valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z' or a network share in the format: \\server\share</param>

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Check string.IsNullOrWhiteSpace(drivePath) before constructing DiskSpaceInfo
  2. Fix the upstream source that produced the null/empty string (missing config value, failed lookup)
  3. Handle empty enumeration results before constructing drive info objects

Example fix

// before
var dsi = new DiskSpaceInfo(userInput);
// after
if (string.IsNullOrWhiteSpace(userInput))
    throw new ArgumentException("A drive path is required.");
var dsi = new DiskSpaceInfo(userInput);
Defensive patterns

Strategy: type-guard

Validate before calling

if (string.IsNullOrWhiteSpace(drivePath))
    throw new ArgumentException("drivePath must be a non-empty drive path like C:\\\\");
var dsi = new DiskSpaceInfo(drivePath);

Type guard

static bool IsValidDrivePath(string p) =>
    !string.IsNullOrWhiteSpace(p) &&
    !string.IsNullOrEmpty(Path.GetPathRoot(Path.IsPathRooted(p) ? p : p + "\\"));

Try / catch

try { var dsi = new DiskSpaceInfo(drivePath); }
catch (ArgumentNullException ex) { log.Error("drivePath was null/empty", ex); }

Prevention

When it happens

Trigger: Calling new DiskSpaceInfo(null), new DiskSpaceInfo(""), or new DiskSpaceInfo(" "); typically from a variable that failed to populate before construction.

Common situations: Enumerating drives where a lookup returns null; parsing command-line args that omitted a drive; string.Split producing an empty entry; a registry/config value that is blank.

Related errors


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