peass-ng/PEASS-ng · error · ArgumentException

Resources.InvalidDriveLetterArgument

Error message

Resources.InvalidDriveLetterArgument

What it means

After normalizing the input (single letter gets VolumeSeparatorChar appended, otherwise GetPathRoot is applied), DiskSpaceInfo throws ArgumentException with Resources.InvalidDriveLetterArgument when the normalized path is still null/empty — i.e. the string was non-blank but not a real drive path. GetPathRoot returns empty for malformed inputs like ":::" on some .NET versions.

Source

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

      [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>
      /// <param name="spaceInfoType"><c>null</c> gets both size- and disk cluster information. <c>true</c> Get only disk cluster information, <c>false</c> Get only size information.</param>
      /// <param name="refresh">Refreshes the state of the object.</param>
      /// <param name="continueOnException"><c>true</c> suppress any Exception that might be thrown as a result from a failure, such as unavailable resources.</param>
      [SecurityCritical]
      public DiskSpaceInfo(string drivePath, bool? spaceInfoType, bool refresh, bool continueOnException) : this(drivePath)
      {

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a proper drive root such as 'C:\\' or 'C:' (single letters are auto-completed)
  2. Validate with Path.GetPathRoot(path) and check it is non-empty before constructing
  3. Strip invalid characters from user input before passing it
  4. For UNC shares include the full '\\\\server\\share\\' form

Example fix

// before
var dsi = new DiskSpaceInfo(pathBox.Text.Trim()); // e.g. "download folder"
// after
var root = Path.GetPathRoot(pathBox.Text.Trim());
if (string.IsNullOrEmpty(root))
    throw new ArgumentException("Enter a valid drive root like C:\\\\.");
var dsi = new DiskSpaceInfo(root);
Defensive patterns

Strategy: type-guard

Validate before calling

var root = Path.GetPathRoot(drivePath);
if (string.IsNullOrEmpty(root))
    throw new ArgumentException("Not a valid drive root: " + drivePath);
var dsi = new DiskSpaceInfo(root);

Type guard

static bool IsDriveRoot(string p)
{
    if (string.IsNullOrWhiteSpace(p)) return false;
    var root = Path.GetPathRoot(p.Length == 1 ? p + ":" : p);
    return !string.IsNullOrEmpty(root);
}

Try / catch

try { var dsi = new DiskSpaceInfo(drivePath); }
catch (ArgumentException ex) { log.Error("Invalid drive letter/path: " + drivePath, ex); }

Prevention

When it happens

Trigger: new DiskSpaceInfo("C") without separator is OK, but new DiskSpaceInfo(":\\"), new DiskSpaceInfo("123"), or a UNC/relative path from which GetPathRoot yields an empty root triggers this.

Common situations: Users pass 'C:' without backslash in environments where GetPathRoot can't resolve it, pass a device path like \\.\PhysicalDrive0 that GetPathRoot mangles, or pass a URL/relative folder path instead of a drive root.

Related errors


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