peass-ng/PEASS-ng · error · ArgumentException
Resources.InvalidDriveLetterArgument
Error message
Resources.InvalidDriveLetterArgument
What it means
After normalizing driveName (single letter + ':' or GetPathRoot), DriveInfo throws ArgumentException with Resources.InvalidDriveLetterArgument when the normalized result is still blank — the string was non-empty but not a recognizable drive root.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DriveInfo.cs:72
/// <exception cref="ArgumentNullException"/>
/// <exception cref="ArgumentException"/>
/// <param name="driveName">
/// A valid drive path or drive letter.
/// <para>This can be either uppercase or lowercase,</para>
/// <para>'a' to 'z' or a network share in the format: \\server\share</para>
/// </param>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Utils.IsNullOrWhiteSpace validates arguments.")]
[SecurityCritical]
public DriveInfo(string driveName)
{
if (Utils.IsNullOrWhiteSpace(driveName))
throw new ArgumentNullException("driveName");
driveName = driveName.Length == 1 ? driveName + Path.VolumeSeparatorChar : Path.GetPathRoot(driveName, false);
if (Utils.IsNullOrWhiteSpace(driveName))
throw new ArgumentException(Resources.InvalidDriveLetterArgument, "driveName");
_name = Path.AddTrailingDirectorySeparator(driveName, false);
// Initiate VolumeInfo() lazyload instance.
_volumeInfo = new VolumeInfo(_name, false, true);
// Initiate DiskSpaceInfo() lazyload instance.
_dsi = new DiskSpaceInfo(_name, null, false, true);
}
#endregion // Constructors
#region Properties
/// <summary>Indicates the amount of available free space on a drive.</summary>
/// <returns>The amount of free space available on the drive, in bytes.</returns>View on GitHub (pinned to 53fb989abc)
Solutions
- Pass a valid drive root: 'C:\\', 'C:', or a complete UNC '\\\\server\\share\\'
- Pre-validate with Path.GetPathRoot and reject empty roots before construction
- Verify mapped drives exist (disconnected mappings may not normalize correctly)
- Use DriveInfo.GetDrives() to list valid drive names instead of guessing
Example fix
// before
var di = new DriveInfo(selectedItem); // "Data (E:)" label from UI
// after
var di = new DriveInfo(DriveInfo.GetDrives()
.First(d => d.Name.Equals("E:\\\\", StringComparison.OrdinalIgnoreCase)).Name); Defensive patterns
Strategy: type-guard
Validate before calling
var root = Path.GetPathRoot(driveName.Length == 1 ? driveName + ":" : driveName);
if (string.IsNullOrEmpty(root))
throw new ArgumentException("Not a valid drive: " + driveName);
var di = new DriveInfo(root); Type guard
static bool IsValidDriveName(string n) =>
!string.IsNullOrWhiteSpace(n) &&
!string.IsNullOrEmpty(Path.GetPathRoot(n.Length == 1 ? n + ":" : n)); Try / catch
try { var di = new DriveInfo(driveName); }
catch (ArgumentException ex) { log.Error("Invalid drive name: " + driveName, ex); } Prevention
- Use DriveInfo.GetDrives() to obtain valid names instead of free-form input
- Strip UI labels down to the bare drive root
- Prefer 'C:\\' style roots; validate single letters before passing
When it happens
Trigger: new DriveInfo("not-a-drive"), new DriveInfo("long relative path"), or inputs where Path.GetPathRoot returns an empty string; also malformed device-style paths.
Common situations: Passing a folder path instead of a drive root; passing a mapped-drive label that is disconnected; localized or typo'd drive letters; passing UNC paths missing segments.
Related errors
- Resources.InvalidDriveLetterArgument
- drivePath
- driveName
- Resources.No_Drive_Letters_Available
- deviceName
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/c68179196720f426.
Report an issue: GitHub.