OrchardCMS/OrchardCore · error · FileStoreException

Cannot get directories with path

Error message

Cannot get directories with path '{path}'.

What it means

FileSystemStore.GetDirectoriesAsync lists only subdirectories under a path and wraps enumeration exceptions in a FileStoreException with this message. A path with no subdirectories returns empty rather than throwing; this error indicates an I/O failure during listing.

Solutions

  1. Read the InnerException: UnauthorizedAccessException -> fix ACLs; DirectoryNotFoundException -> path removed; IOException -> lock or device issue.
  2. Grant the app identity list permissions recursively over the storage root.
  3. Sanitize folder names (strip invalid path characters) when creating folders from user input.
  4. Verify the path exists first via GetDirectoryInfoAsync.

Example fix

// before
var dirs = fileStore.GetDirectoriesAsync(path);
await foreach (var d in dirs) { ... }
// after
try
{
    var dirs = fileStore.GetDirectoriesAsync(path);
    await foreach (var d in dirs) { ... }
}
catch (FileStoreException ex)
{
    logger.LogWarning(ex.InnerException, "Could not list directories under {Path}", path);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (await fileStore.GetDirectoryInfoAsync(path) == null)
{
    return AsyncEnumerable.Empty<IFileStoreEntry>();
}

Try / catch

try
{
    await foreach (var d in fileStore.GetDirectoriesAsync(path)) { /* ... */ }
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException, "Directory listing failed for {Path}", path);
}

Prevention

When it happens

Trigger: Calling IFileStore.GetDirectoriesAsync(path) when Directory.EnumerateDirectories throws: UnauthorizedAccessException on an unreadable subfolder, invalid/too-long path, directory deleted during enumeration, or volume/device errors.

Common situations: Media library folder tree broken by ACL changes; enumerating folders on a disconnected network share; invalid characters introduced by user-created folder names; indexer/AV interference.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/c713c9df7b2900d3. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:167

            {
                return Array.Empty<IFileStoreEntry>().ToAsyncEnumerable();
            }

            var results = Directory
                .GetDirectories(physicalPath, "*", SearchOption.TopDirectoryOnly)
                .Select(f =>
                {
                    var fileSystemInfo = new PhysicalDirectoryInfo(new DirectoryInfo(f));
                    var fileRelativePath = f[_fileSystemPath.Length..];
                    var filePath = this.NormalizePath(fileRelativePath);
                    return (IFileStoreEntry)new FileSystemStoreEntry(filePath, fileSystemInfo);
                });

            return results.ToAsyncEnumerable();
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot get directories with path '{path}'.", ex);
        }
    }

    public Task<bool> TryCreateDirectoryAsync(string path)
    {
        try
        {
            var physicalPath = GetPhysicalPath(path);

            if (File.Exists(physicalPath))
            {
                throw new FileStoreException($"Cannot create directory because the path '{path}' already exists and is a file.");
            }

            if (Directory.Exists(physicalPath))
            {
                return Task.FromResult(false);
            }

View on GitHub (pinned to 4306c0717f)