{"record":{"id":"c68179196720f426","repo":"peass-ng/PEASS-ng","slug":"resources-invaliddriveletterargument-c68179","errorCode":null,"errorMessage":"Resources.InvalidDriveLetterArgument","messagePattern":"Resources\\.InvalidDriveLetterArgument","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DriveInfo.cs","lineNumber":72,"sourceCode":"      /// <exception cref=\"ArgumentNullException\"/>\n      /// <exception cref=\"ArgumentException\"/>\n      /// <param name=\"driveName\">\n      ///   A valid drive path or drive letter.\n      ///   <para>This can be either uppercase or lowercase,</para>\n      ///   <para>'a' to 'z' or a network share in the format: \\\\server\\share</para>\n      /// </param>\n      [SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\", Justification = \"Utils.IsNullOrWhiteSpace validates arguments.\")]\n      [SecurityCritical]\n      public DriveInfo(string driveName)\n      {\n         if (Utils.IsNullOrWhiteSpace(driveName))\n            throw new ArgumentNullException(\"driveName\");\n\n\n         driveName = driveName.Length == 1 ? driveName + Path.VolumeSeparatorChar : Path.GetPathRoot(driveName, false);\n\n         if (Utils.IsNullOrWhiteSpace(driveName))\n            throw new ArgumentException(Resources.InvalidDriveLetterArgument, \"driveName\");\n\n\n         _name = Path.AddTrailingDirectorySeparator(driveName, false);\n\n         // Initiate VolumeInfo() lazyload instance.\n         _volumeInfo = new VolumeInfo(_name, false, true);\n\n         // Initiate DiskSpaceInfo() lazyload instance.\n         _dsi = new DiskSpaceInfo(_name, null, false, true);\n      }\n\n      #endregion // Constructors\n\n\n      #region Properties\n\n      /// <summary>Indicates the amount of available free space on a drive.</summary>\n      /// <returns>The amount of free space available on the drive, in bytes.</returns>","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DriveInfo.cs#L54-L90","documentation":"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.","triggerScenarios":"new DriveInfo(\"not-a-drive\"), new DriveInfo(\"long relative path\"), or inputs where Path.GetPathRoot returns an empty string; also malformed device-style paths.","commonSituations":"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.","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"],"exampleFix":"// before\nvar di = new DriveInfo(selectedItem); // \"Data (E:)\" label from UI\n// after\nvar di = new DriveInfo(DriveInfo.GetDrives()\n    .First(d => d.Name.Equals(\"E:\\\\\\\\\", StringComparison.OrdinalIgnoreCase)).Name);","handlingStrategy":"type-guard","validationCode":"var root = Path.GetPathRoot(driveName.Length == 1 ? driveName + \":\" : driveName);\nif (string.IsNullOrEmpty(root))\n    throw new ArgumentException(\"Not a valid drive: \" + driveName);\nvar di = new DriveInfo(root);","typeGuard":"static bool IsValidDriveName(string n) =>\n    !string.IsNullOrWhiteSpace(n) &&\n    !string.IsNullOrEmpty(Path.GetPathRoot(n.Length == 1 ? n + \":\" : n));","tryCatchPattern":"try { var di = new DriveInfo(driveName); }\ncatch (ArgumentException ex) { log.Error(\"Invalid drive name: \" + driveName, ex); }","preventionTips":["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"],"tags":["csharp","argument-exception","alphafs","drive-path"],"backgroundTag":"invalid-drive-path","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}