peass-ng/PEASS-ng · error · NotSupportedException

Resources.Unsupported_Path_Format

Error message

Resources.Unsupported_Path_Format

What it means

Inside CreateDirectoryCore, when the native Win32 call fails with ERROR_DIRECTORY, AlphaFS throws NotSupportedException reporting that the path format is unsupported. Per MSDN this corresponds to path containing a colon character (':' ) that is not part of a drive label (e.g. "C:\"). AlphaFS maps that native error to Resources.Unsupported_Path_Format with the offending long path.

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory Core Methods/Directory.CreateDirectoryCore.cs:142

                     // MSDN: .NET 3.5+: If the directory already exists, this method does nothing.
                     // MSDN: .NET 3.5+: IOException: The directory specified by path is a file.
                     case Win32Errors.ERROR_ALREADY_EXISTS:
                        if (File.ExistsCore(transaction, false, longPath, PathFormat.LongFullPath))
                           NativeError.ThrowException(lastError, longPath);

                        if (File.ExistsCore(transaction, false, folderLp, PathFormat.LongFullPath))
                           NativeError.ThrowException(Win32Errors.ERROR_PATH_NOT_FOUND, null, folderLp);
                        break;


                     case Win32Errors.ERROR_BAD_NET_NAME:
                        NativeError.ThrowException(Win32Errors.ERROR_BAD_NET_NAME, longPath);
                        break;


                     case Win32Errors.ERROR_DIRECTORY:
                        // MSDN: .NET 3.5+: NotSupportedException: path contains a colon character (:) that is not part of a drive label ("C:\").
                        throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Resources.Unsupported_Path_Format, longPath));


                     case Win32Errors.ERROR_ACCESS_DENIED:
                        // Report the parent folder, the inaccessible folder.
                        var parent = GetParent(folderLp);

                        NativeError.ThrowException(lastError, null != parent ? parent.FullName : folderLp);
                        break;


                     default:
                        NativeError.ThrowException(lastError, true, folderLp);
                        break;
                  }
               }

               else if (compress)
                  Device.ToggleCompressionCore(transaction, true, folderLp, true, PathFormat.LongFullPath);

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Remove or replace the illegal colon in the path; sanitize user-supplied folder names (strip ':' or replace with '-').
  2. If a URI was passed, convert to a local filesystem path first (e.g. uri.LocalPath) or use appropriate network APIs instead.
  3. Validate the path with Path.GetInvalidPathChars / a regex allowing ':' only at index 1 (drive label) before calling.
  4. Catch NotSupportedException to surface a friendly message identifying the bad path (the exception message embeds longPath).

Example fix

// before
Directory.CreateDirectory($"C:\\logs\\{DateTime.Now.ToString("HH:mm")}");
// after
Directory.CreateDirectory($"C:\\logs\\{DateTime.Now.ToString("HH-mm")}");
Defensive patterns

Strategy: validation

Validate before calling

static void EnsureNoIllegalColon(string path)
{
    // ':' only allowed as drive separator at index 1
    for (int i = 0; i < path.Length; i++)
        if (path[i] == ':' && i != 1)
            throw new ArgumentException($"Illegal ':' at position {i} in '{path}'");
}
EnsureNoIllegalColon(path);
Directory.CreateDirectory(path);

Type guard

static bool IsWellFormedLocalPath(string p) =>
    !string.IsNullOrEmpty(p) && p.IndexOf(':') is -1 or 1;

Try / catch

try
{
    Directory.CreateDirectory(path);
}
catch (NotSupportedException ex)
{
    // message embeds the offending longPath
    throw new InvalidOperationException($"Path contains an unsupported character (stray ':'): {path}", ex);
}

Prevention

When it happens

Trigger: Calling Directory.CreateDirectory (or CreateDirectoryTransacted / CreateJunction which call the core) with a path containing an illegal colon, e.g. "C:\dir\name:stream" (NTFS alternate data stream syntax) or "http://server/path".

Common situations: Passing URL/URI strings directly as directory paths; accidentally building paths with time strings like "12:30" in the folder name; alternate-data-stream style names; path assembled from user input containing ':' on a non-drive position.

Related errors


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