peass-ng/PEASS-ng · error · ArgumentException

Resources.InvalidDriveLetterArgument

Error message

Resources.InvalidDriveLetterArgument

What it means

After normalizing volumeName (adding LongPathPrefix, converting UNC, or extracting the path root), the VolumeInfo constructor re-checks the result. If it is still null or whitespace, it throws ArgumentException(Resources.InvalidDriveLetterArgument, "volumeName"), meaning the input did not resolve to a usable drive letter or volume root.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/VolumeInfo.cs:67

      {
         if (Utils.IsNullOrWhiteSpace(volumeName))
            throw new ArgumentNullException("volumeName");


         if (!volumeName.StartsWith(Path.LongPathPrefix, StringComparison.Ordinal))
            volumeName = Path.IsUncPathCore(volumeName, false, false) ? Path.GetLongPathCore(volumeName, GetFullPathOptions.None) : Path.LongPathPrefix + volumeName;

         else
         {
            volumeName = volumeName.Length == 1 ? volumeName + Path.VolumeSeparatorChar : Path.GetPathRoot(volumeName, false);

            if (!volumeName.StartsWith(Path.GlobalRootPrefix, StringComparison.OrdinalIgnoreCase))
               volumeName = Path.GetPathRoot(volumeName, false);
         }


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


         Name = Path.AddTrailingDirectorySeparator(volumeName, false);

         _volumeHandle = null;
      }


      /// <summary>Initializes a VolumeInfo instance.</summary>
      /// <param name="driveName">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="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 VolumeInfo(string driveName, bool refresh, bool continueOnException) : this(driveName)
      {
         _continueOnAccessError = continueOnException;

         if (refresh)

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a full root path with trailing separator: "C:\" instead of "C".
  2. For UNC, include both server and share: "\\\\server\\share\\".
  3. Validate beforehand that Path.GetPathRoot(value) returns a non-empty result, or catch ArgumentException and surface a message asking for a valid drive letter.

Example fix

// before
var info = new VolumeInfo("C"); // no root separator
// after
string root = Path.GetPathRoot("C:\\some\\path"); // "C:\"
if (!string.IsNullOrWhiteSpace(root))
    var info = new VolumeInfo(root);
Defensive patterns

Strategy: validation

Validate before calling

string root = Path.GetPathRoot(volumeName);
if (!string.IsNullOrWhiteSpace(root) && root != volumeName.TrimEnd('\\') + "\\")
{
    var info = new VolumeInfo(root);
}

Type guard

static bool ResolvesToDriveRoot(string s) =>
    !string.IsNullOrWhiteSpace(s) && !string.IsNullOrWhiteSpace(Path.GetPathRoot(s));

Try / catch

try { var info = new VolumeInfo(volumeName); }
catch (ArgumentException ex) when (ex.ParamName == "volumeName")
{
    // input did not resolve to a drive root; prompt for a valid drive letter
}

Prevention

When it happens

Trigger: Passing a string that survives null checks but is not a real drive path: e.g. "C" without a separator in a code path where GetPathRoot returned empty, a UNC fragment like "\\\\server" without a share, or a prefix-only string like "\\\\?\" or "\\\\.\".

Common situations: Parsing paths from logs or user input where only a drive letter (no backslash) was captured; network shares where the share component was stripped; virtual device paths (\\\\.\PhysicalDrive0) fed to a constructor expecting a file-system volume root.

Related errors


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