peass-ng/PEASS-ng · error · ArgumentNullException
path
Error message
path
What it means
AlphaFS's Directory.CreateDirectoryCore validates the input path before touching the filesystem. When the path argument is null and the caller did not request LongFullPath format, it throws ArgumentNullException('path'). The library requires a non-null path string (or PathFormat.LongFullPath to skip normalization, which still needs a valid path downstream).
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateDirectoryCore.cs:64
/// <exception cref="IOException"/>
/// <exception cref="NotSupportedException"/>
/// <exception cref="UnauthorizedAccessException"/>
/// <param name="returnNull">When <c>true</c> returns <c>null</c> instead of a <see cref="DirectoryInfo"/> instance.</param>
/// <param name="transaction">The transaction.</param>
/// <param name="path">The directory to create.</param>
/// <param name="templatePath">The path of the directory to use as a template when creating the new directory. May be <c>null</c> to indicate that no template should be used.</param>
/// <param name="directorySecurity">The <see cref="DirectorySecurity"/> access control to apply to the directory, may be null.</param>
/// <param name="compress">When <c>true</c> compresses the directory using NTFS compression.</param>
/// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
[SecurityCritical]
internal static DirectoryInfo CreateDirectoryCore(bool returnNull, KernelTransaction transaction, string path, string templatePath, ObjectSecurity directorySecurity, bool compress, PathFormat pathFormat)
{
var longPath = path;
if (pathFormat != PathFormat.LongFullPath)
{
if (null == path)
throw new ArgumentNullException("path");
Path.CheckSupportedPathFormat(path, true, true);
Path.CheckSupportedPathFormat(templatePath, true, true);
longPath = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);
pathFormat = PathFormat.LongFullPath;
}
if (!char.IsWhiteSpace(longPath[longPath.Length - 1]))
{
// Return DirectoryInfo instance if the directory specified by path already exists.
if (File.ExistsCore(transaction, true, longPath, PathFormat.LongFullPath))
// We are not always interested in a new DirectoryInfo instance.View on GitHub (pinned to 53fb989abc)
Solutions
- Ensure the path argument is non-null before calling: if (string.IsNullOrEmpty(path)) throw/return or supply a default.
- Coalesce nulls at the call site: path ?? defaultPath.
- Guard the source of the path (config read, registry, user input) and fail fast with a clear message instead of reaching the library.
- If you intentionally pass raw paths, use the PathFormat.LongFullPath overload only with a genuinely non-null path.
Example fix
// before
Directory.CreateDirectory(myConfig.Path);
// after
if (string.IsNullOrWhiteSpace(myConfig.Path))
throw new InvalidOperationException("Config 'Path' is not set");
Directory.CreateDirectory(myConfig.Path); Defensive patterns
Strategy: validation
Validate before calling
if (path == null)
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Path must not be empty", nameof(path));
Directory.CreateDirectory(path); Type guard
static bool IsValidPathArg(string p) => !string.IsNullOrWhiteSpace(p);
Try / catch
try
{
Directory.CreateDirectory(path);
}
catch (ArgumentNullException ex)
{
// ex.ParamName == "path": caller supplied a null path
logger.LogError(ex, "CreateDirectory called with null path");
} Prevention
- Never pass nullable strings straight into path APIs; coalesce or throw at the boundary.
- Validate configuration at startup so missing path keys fail before use.
- Enable nullable reference types (C# 8+) so null paths are caught at compile time.
- Centralize directory-creation in a helper that guards empty/null.
When it happens
Trigger: Calling Directory.CreateDirectory / CreateDirectoryTransacted / CreateJunction (which funnel into CreateDirectoryCore) with a null path string while using the default PathFormat (LongFullPath-less) overload.
Common situations: Path assembled from config/appsettings where a key is missing; null return from Environment.GetFolderPath or a lookup; passing an uninitialized variable or a nullable path that was never coalesced; refactored code that dropped a default value.
Related errors
- Resources.Cannot_Create_Directory
- Resources.Unsupported_Path_Format
- drivePath
- Resources.InvalidDriveLetterArgument
- driveName
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/b3820ed8bfa8eef0.
Report an issue: GitHub.