peass-ng/PEASS-ng · error · ArgumentNullException
driveName
Error message
driveName
What it means
AlphaFS's DriveInfo constructor throws ArgumentNullException with param name 'driveName' when the drive name is null, empty, or whitespace. Like DiskSpaceInfo, it validates eagerly at construction time.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DriveInfo.cs:66
[NonSerialized] private readonly string _name;
#region Constructors
/// <summary>Provides access to information on the specified drive.</summary>
/// <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 // ConstructorsView on GitHub (pinned to 53fb989abc)
Solutions
- Check string.IsNullOrWhiteSpace(driveName) before constructing DriveInfo
- Fix the source producing the empty string (missing config, failed lookup)
- Filter empty entries out of collections before constructing DriveInfo objects
Example fix
// before
foreach (var name in names) drives.Add(new DriveInfo(name));
// after
foreach (var name in names.Where(n => !string.IsNullOrWhiteSpace(n)))
drives.Add(new DriveInfo(name)); Defensive patterns
Strategy: type-guard
Validate before calling
if (string.IsNullOrWhiteSpace(driveName))
throw new ArgumentException("driveName must be a non-empty drive name like C:");
var di = new DriveInfo(driveName); Type guard
static bool IsValidDriveName(string n) =>
!string.IsNullOrWhiteSpace(n) &&
System.Text.RegularExpressions.Regex.IsMatch(n.Trim(), "^[A-Za-z]:?$"); Try / catch
try { var di = new DriveInfo(driveName); }
catch (ArgumentNullException ex) { log.Error("driveName was null/empty", ex); } Prevention
- Check IsNullOrWhiteSpace before construction
- Skip empty entries when enumerating name lists
- Validate UI text boxes before binding to DriveInfo
When it happens
Trigger: new DriveInfo(null), new DriveInfo(""), or new DriveInfo("\t") — usually a variable that was never assigned or an empty result from parsing.
Common situations: Iterating a list where an entry is empty; settings/registry value missing; WinForms TextBox left blank; splitting a string that yields an empty element.
Related errors
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/49f0d09575c3fff5.
Report an issue: GitHub.