peass-ng/PEASS-ng · error · ArgumentNullException

volumeName

Error message

volumeName

What it means

The VolumeInfo constructor requires a non-empty volumeName (drive path, drive letter, or UNC share) because all subsequent path normalization depends on it. It throws ArgumentNullException naming volumeName when the value is null, empty, or whitespace. This is a fail-fast guard before GetLongPathCore / prefix normalization runs.

Source

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

   [Serializable]
   [SecurityCritical]
   public sealed class VolumeInfo
   {
      [NonSerialized] private readonly bool _continueOnAccessError;
      [NonSerialized] private readonly SafeFileHandle _volumeHandle;
      [NonSerialized] private NativeMethods.VOLUME_INFO_FLAGS _volumeInfoAttributes;


      /// <summary>Initializes a VolumeInfo instance.</summary>
      /// <exception cref="ArgumentNullException"/>
      /// <exception cref="ArgumentException"/>
      /// <param name="volumeName">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>
      [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
      [SecurityCritical]
      public VolumeInfo(string volumeName)
      {
         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");

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a valid drive root like "C:\" or a UNC path like "\\\\server\\share".
  2. Check the drive exists first (DriveInfo.IsReady or GetDrives()) before constructing VolumeInfo.
  3. Validate with string.IsNullOrWhiteSpace and fall back to a default volume or skip the entry.

Example fix

// before
var info = new VolumeInfo(drive.RootDirectory.Name); // drive may be gone
// after
var di = new DriveInfo("C");
if (di.IsReady)
{
    var info = new VolumeInfo(di.RootDirectory.FullName);
}
else
{
    // skip or log: volume unavailable
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(volumeName))
    throw new ArgumentException("volumeName required, e.g. C:\\ or \\\\server\\share");
var info = new VolumeInfo(volumeName);

Type guard

static bool IsValidVolumeName(string s) =>
    !string.IsNullOrWhiteSpace(s) &&
    (s.StartsWith("\\\\", StringComparison.Ordinal) ||
     (s.Length >= 2 && char.IsLetter(s[0]) && s[1] == ':'));

Try / catch

try { var info = new VolumeInfo(volumeName); }
catch (ArgumentNullException ex) when (ex.ParamName == "volumeName")
{
    // missing drive path; skip entry or use default volume
}

Prevention

When it happens

Trigger: new VolumeInfo(null), new VolumeInfo(""), or whitespace; constructing from DriveInfo properties on a drive that no longer exists, or from a config/env value that resolved to empty.

Common situations: Enumerating drives where a removable device was unplugged between listing and VolumeInfo construction; configuration files with a missing DriveLetter key; passing DriveInfo.Name results from a failed drive query.

Related errors


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