peass-ng/PEASS-ng · error · ArgumentNullException
deviceName
Error message
deviceName
What it means
AlphaFS DefineDosDeviceCore (used by DefineDosDevice and DeleteDosDevice) throws ArgumentNullException with param name 'deviceName' when the DOS device name is null, empty, or whitespace. DefineDosDevice maps a device name (e.g. 'X:') to a target path, so the name is mandatory.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/Volume/Volume.DefineDosDevice.cs:85
/// An MS-DOS device name string specifying the device the function is defining, redefining, or deleting.
/// </param>
/// <param name="targetPath">
/// A pointer to a path string that will implement this device. The string is an MS-DOS path string unless the
/// <see cref="DosDeviceAttributes.RawTargetPath"/> flag is specified, in which case this string is a path string.
/// </param>
/// <param name="deviceAttributes">
/// The controllable aspects of the DefineDosDevice function, <see cref="DosDeviceAttributes"/> flags which will be combined with the
/// default.
/// </param>
/// <param name="exactMatch">
/// Only delete MS-DOS device on an exact name match. If <paramref name="exactMatch"/> is <c>true</c>,
/// <paramref name="targetPath"/> must be the same path used to create the mapping.
/// </param>
[SecurityCritical]
internal static void DefineDosDeviceCore(bool isDefine, string deviceName, string targetPath, DosDeviceAttributes deviceAttributes, bool exactMatch)
{
if (Utils.IsNullOrWhiteSpace(deviceName))
throw new ArgumentNullException("deviceName");
if (isDefine)
{
// targetPath is allowed to be null.
// In no case is a trailing backslash ("\") allowed.
deviceName = Path.GetRegularPathCore(deviceName, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars, false);
using (new NativeMethods.ChangeErrorMode(NativeMethods.ErrorMode.FailCriticalErrors))
{
var success = NativeMethods.DefineDosDevice(deviceAttributes, deviceName, targetPath);
var lastError = Marshal.GetLastWin32Error();
if (!success)
NativeError.ThrowException(lastError, deviceName, targetPath);
}
}
View on GitHub (pinned to 53fb989abc)
Solutions
- Ensure deviceName is a non-empty name like 'X:' before calling; check string.IsNullOrWhiteSpace first
- Verify variable assignment/order of arguments (targetPath is allowed to be null for define, deviceName is not)
- Fix the source of the empty value (UI field, config key, lookup result)
- Pick a free drive letter (e.g. via GetFreeDriveLetter) before mapping instead of passing an unset variable
Example fix
// before
AlphaFS.Device.Volume.DefineDosDevice(freeLetter, targetPath); // freeLetter was null
// after
if (string.IsNullOrWhiteSpace(freeLetter))
freeLetter = DriveInfo.GetFreeDriveLetter() + ":";
AlphaFS.Device.Volume.DefineDosDevice(freeLetter, targetPath); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(deviceName))
throw new ArgumentException("deviceName is required, e.g. \"X:\"");
AlphaFS.Device.Volume.DefineDosDevice(deviceName, targetPath); Type guard
static bool IsValidDosDeviceName(string n) =>
!string.IsNullOrWhiteSpace(n) && n.Trim().Length >= 2; Try / catch
try { AlphaFS.Device.Volume.DefineDosDevice(deviceName, targetPath); }
catch (ArgumentNullException ex) { log.Error("deviceName was null/empty", ex); } Prevention
- Assign a real drive letter (e.g. via GetFreeDriveLetter) before mapping
- Double-check argument order — targetPath may be null for define, deviceName may not
- Validate config/UI values before calling DefineDosDevice/DeleteDosDevice
When it happens
Trigger: DefineDosDevice(...) or DeleteDosDevice(...) with a null/empty deviceName — e.g. an unset drive-letter variable, empty UI field, or a lookup that returned nothing.
Common situations: Automating drive mapping where the chosen letter variable was never assigned; config value blank; calling DeleteDosDevice with the wrong parameter order or an empty string from string.Split.
Related errors
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/7ae16ea68cef3bd2.
Report an issue: GitHub.