OrchardCMS/OrchardCore · error · FileStoreException

Cannot get directory content with path

Error message

Cannot get directory content with path '{path}'.

What it means

BlobFileStore.GetDirectoryContentAsync lists the entries under a path; failures while initiating the listing (or while choosing the flat vs hierarchy path) are wrapped in a FileStoreException with this message. On HNS accounts it delegates to GetDirectoryContentByHierarchyAsync, otherwise it enumerates blobs by prefix. Since it returns IAsyncEnumerable, exceptions surface both at call time and during enumeration.

Solutions

  1. Inspect the inner exception for status; handle 404 as empty result rather than an error where appropriate.
  2. Validate/normalize the path prefix before listing (trim slashes, remove illegal characters).
  3. For large containers, use pagination-friendly consumption and retry on 503/timeout with backoff.
  4. Ensure the UseHierarchicalNamespace setting matches the actual account type (see error 161).

Example fix

// before
await foreach (var e in fileStore.GetDirectoryContentAsync(rawPath)) { } // rawPath may be malformed
// after
var path = string.IsNullOrWhiteSpace(rawPath) ? null : rawPath.Trim('/');
await foreach (var e in fileStore.GetDirectoryContentAsync(path)) { }
Defensive patterns

Strategy: try-catch

Validate before calling

var prefix = string.IsNullOrWhiteSpace(path) ? null : path.Trim('/');
if (prefix != null && prefix.Split('/').Any(string.IsNullOrWhiteSpace))
{
    throw new ArgumentException("Invalid directory path", nameof(path));
}

Try / catch

try
{
    await foreach (var entry in fileStore.GetDirectoryContentAsync(prefix, includeSubDirectories: false)
                                   .WithCancellation(ct))
    {
        // process entry
    }
}
catch (FileStoreException ex)
{
    logger.LogError(ex.InnerException, "Listing failed for {Path}", prefix);
    // return empty page or retry on 503
}

Prevention

When it happens

Trigger: Calling GetDirectoryContentAsync(path, includeSubDirectories) when the blob listing request fails — invalid prefix from malformed path, container missing, auth/network failure, or HNS hierarchy listing failure. Also thrown when enumerating the returned IAsyncEnumerable.

Common situations: Very large containers hitting listing timeouts; throttling (503) under heavy load; paths with trailing/illegal characters; switching an existing site between HNS and flat accounts so the wrong code path is used.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:269

        }
    }

    public IAsyncEnumerable<IFileStoreEntry> GetDirectoryContentAsync(string path = null, bool includeSubDirectories = false)
    {
        try
        {
            if (includeSubDirectories)
            {
                return GetDirectoryContentFlatAsync(path);
            }
            else
            {
                return GetDirectoryContentByHierarchyAsync(path);
            }
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot get directory content with path '{path}'.", ex);
        }
    }

    private async IAsyncEnumerable<IFileStoreEntry> GetDirectoryContentByHierarchyAsync(string path = null)
    {
        await EnsureCapabilitiesAsync();

        path = this.NormalizePath(path);

        var prefix = this.Combine(_basePrefix, path);
        prefix = NormalizePrefix(prefix);

        var page = _blobContainer.GetBlobsByHierarchyAsync(BlobTraits.Metadata, BlobStates.None, "/", prefix, CancellationToken.None);

        await foreach (var blob in page)
        {
            if (blob.IsPrefix)
            {

View on GitHub (pinned to 4306c0717f)