peass-ng/PEASS-ng · error · ArgumentNullException

Value cannot be null. Parameter name: path

Error message

Value cannot be null.
Parameter name: path

What it means

DeleteFileCore validates its 'path' argument and throws ArgumentNullException when it is null. AlphaFS uses explicit guard clauses because native DeleteFile cannot receive a null path. The null propagates from caller code passing an uninitialized path string.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.DeleteFileCore.cs:48

{
   public static partial class File
   {
      /// <summary>Deletes a Non-/Transacted file.</summary>
      /// <remarks>If the file to be deleted does not exist, no exception is thrown.</remarks>
      /// <exception cref="ArgumentException"/>
      /// <exception cref="NotSupportedException"/>
      /// <exception cref="UnauthorizedAccessException"/>
      /// <exception cref="FileReadOnlyException"/>
      /// <param name="transaction">The transaction.</param>
      /// <param name="path">The name of the file to be deleted.</param>
      /// <param name="ignoreReadOnly"><c>true</c> overrides the read only <see cref="FileAttributes"/> of the file.</param>
      /// <param name="attributes"></param>
      /// <param name="pathFormat">Indicates the format of the path parameter(s).</param>
      [SecurityCritical]
      internal static void DeleteFileCore(KernelTransaction transaction, string path, bool ignoreReadOnly, FileAttributes attributes, PathFormat pathFormat)
      {
         if (null == path)
            throw new ArgumentNullException("path");

         if (pathFormat == PathFormat.RelativePath)
            Path.CheckSupportedPathFormat(path, true, true);

         var pathLp = Path.GetExtendedLengthPathCore(transaction, path, pathFormat, GetFullPathOptions.TrimEnd | GetFullPathOptions.RemoveTrailingDirectorySeparator);


         // Reset attributes to Normal if we already know the facts.

         if (ignoreReadOnly && IsReadOnlyOrHidden(attributes))

            SetAttributesCore(transaction, false, pathLp, FileAttributes.Normal, PathFormat.LongFullPath);


      startDeleteFile:

         if (!(null == transaction || !NativeMethods.IsAtLeastWindowsVista

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Initialize or obtain a valid non-null path before calling File.Delete
  2. Add a null check on the path before invoking the delete
  3. Fix the upstream code that produced the null path (e.g. failed config read)

Example fix

// before
string path = GetPathFromConfig();
File.Delete(path);
// after
string path = GetPathFromConfig();
if (string.IsNullOrEmpty(path)) throw new InvalidOperationException("path not configured");
File.Delete(path);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(path)) throw new ArgumentException("path must be provided", nameof(path));

Type guard

bool IsValidPath(string p) => !string.IsNullOrWhiteSpace(p) && p.IndexOfAny(Path.GetInvalidPathChars()) < 0;

Try / catch

try { File.Delete(path); }
catch (ArgumentNullException ex) { Log("null path passed to delete: " + ex.ParamName); }

Prevention

When it happens

Trigger: Calling File.Delete(path) or File.DeleteTransacted(transaction, path) with a null path string (e.g. from a failed lookup, uninitialized variable, or Split/substring producing null).

Common situations: Registry or config values read as null and fed directly into File.Delete; a search result returned no path; variables declared but never assigned before cleanup code runs.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/263f832142eee774. Report an issue: GitHub.