{"record":{"id":"96a055611d529a4d","repo":"OrchardCMS/OrchardCore","slug":"cannot-get-directory-content-with-path-path","errorCode":null,"errorMessage":"Cannot get directory content with path '{path}'.","messagePattern":"Cannot get directory content with path '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs","lineNumber":269,"sourceCode":"        }\n    }\n\n    public IAsyncEnumerable<IFileStoreEntry> GetDirectoryContentAsync(string path = null, bool includeSubDirectories = false)\n    {\n        try\n        {\n            if (includeSubDirectories)\n            {\n                return GetDirectoryContentFlatAsync(path);\n            }\n            else\n            {\n                return GetDirectoryContentByHierarchyAsync(path);\n            }\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot get directory content with path '{path}'.\", ex);\n        }\n    }\n\n    private async IAsyncEnumerable<IFileStoreEntry> GetDirectoryContentByHierarchyAsync(string path = null)\n    {\n        await EnsureCapabilitiesAsync();\n\n        path = this.NormalizePath(path);\n\n        var prefix = this.Combine(_basePrefix, path);\n        prefix = NormalizePrefix(prefix);\n\n        var page = _blobContainer.GetBlobsByHierarchyAsync(BlobTraits.Metadata, BlobStates.None, \"/\", prefix, CancellationToken.None);\n\n        await foreach (var blob in page)\n        {\n            if (blob.IsPrefix)\n            {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs#L251-L287","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the inner exception for status; handle 404 as empty result rather than an error where appropriate.","Validate/normalize the path prefix before listing (trim slashes, remove illegal characters).","For large containers, use pagination-friendly consumption and retry on 503/timeout with backoff.","Ensure the UseHierarchicalNamespace setting matches the actual account type (see error 161)."],"exampleFix":"// before\nawait foreach (var e in fileStore.GetDirectoryContentAsync(rawPath)) { } // rawPath may be malformed\n// after\nvar path = string.IsNullOrWhiteSpace(rawPath) ? null : rawPath.Trim('/');\nawait foreach (var e in fileStore.GetDirectoryContentAsync(path)) { }","handlingStrategy":"try-catch","validationCode":"var prefix = string.IsNullOrWhiteSpace(path) ? null : path.Trim('/');\nif (prefix != null && prefix.Split('/').Any(string.IsNullOrWhiteSpace))\n{\n    throw new ArgumentException(\"Invalid directory path\", nameof(path));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await foreach (var entry in fileStore.GetDirectoryContentAsync(prefix, includeSubDirectories: false)\n                                   .WithCancellation(ct))\n    {\n        // process entry\n    }\n}\ncatch (FileStoreException ex)\n{\n    logger.LogError(ex.InnerException, \"Listing failed for {Path}\", prefix);\n    // return empty page or retry on 503\n}","preventionTips":["Remember exceptions can surface during enumeration, not only at the call — wrap the await foreach.","Handle 404 as empty listing for missing prefixes if acceptable in your flow.","For big containers, page through results and add backoff on throttling.","Keep HNS setting consistent with the account to avoid hierarchy-path failures."],"tags":["azure","blob-storage","file-storage","listing","network"],"backgroundTag":"http-error-response","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}