{"record":{"id":"d829a265f30c33ff","repo":"OrchardCMS/OrchardCore","slug":"cannot-delete-directory-path","errorCode":null,"errorMessage":"Cannot delete directory '{path}'.","messagePattern":"Cannot delete directory '(.+?)'\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs","lineNumber":511,"sourceCode":"                if (!await directoryClient.ExistsAsync())\n                {\n                    return false;\n                }\n\n                await directoryClient.DeleteAsync(recursive: true);\n                return true;\n            }\n            catch (FileStoreException)\n            {\n                throw;\n            }\n            catch (RequestFailedException ex) when (ex.Status == 404)\n            {\n                return false;\n            }\n            catch (Exception ex)\n            {\n                throw new FileStoreException($\"Cannot delete directory '{path}'.\", ex);\n            }\n        }\n\n        try\n        {\n            if (string.IsNullOrEmpty(path))\n            {\n                throw new FileStoreException(\"Cannot delete the root directory.\");\n            }\n\n            var blobsWereDeleted = false;\n            var prefix = this.Combine(_basePrefix, path);\n            prefix = NormalizePrefix(prefix);\n\n            var page = _blobContainer.GetBlobsAsync(BlobTraits.Metadata, BlobStates.None, prefix, CancellationToken.None);\n            await foreach (var blob in page)\n            {\n                var blobReference = _blobContainer.GetBlobClient(blob.Name);","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs#L493-L529","documentation":"Wrapping FileStoreException from the hierarchical-namespace (ADLS Gen2) branch of TryDeleteDirectoryAsync. Any unexpected exception while deleting a Data Lake directory (other than the handled 404) is rethrown with the directory path in the message and the original exception as InnerException.","triggerScenarios":"Calling TryDeleteDirectoryAsync on an HNS-enabled account when the Data Lake directory client throws: authorization failures (403), throttling (429), transient network/RequestFailedException with non-404 status, or invalid path characters.","commonSituations":"Missing storage account keys/credentials or insufficient RBAC rights (Storage Blob Data Contributor); container deleted underneath the store; transient Azure outages; misconfigured base prefix producing invalid directory names.","solutions":["Inspect InnerException (RequestFailedException status) to identify the real cause.","Verify credentials/RBAC role on the storage account and container.","Check that the container and base prefix exist and the path is valid.","Add retry logic (Polly or Azure SDK Retry options) for transient 5xx/429 errors."],"exampleFix":"// before\nawait _fileStore.TryDeleteDirectoryAsync(path);\n// after\ntry\n{\n    await _fileStore.TryDeleteDirectoryAsync(path);\n}\ncatch (FileStoreException ex)\n{\n    _logger.LogError(ex.InnerException, \"Failed to delete directory {Path}\", path);\n}","handlingStrategy":"try-catch","validationCode":"if (await _fileStore.DirectoryExistsAsync(path))\n{\n    await _fileStore.TryDeleteDirectoryAsync(path);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await _fileStore.TryDeleteDirectoryAsync(path);\n}\ncatch (FileStoreException ex)\n{\n    var azureError = ex.InnerException as RequestFailedException;\n    _logger.LogError(ex, \"Delete failed for {Path} (status {Status})\", path, azureError?.Status);\n}","preventionTips":["Grant the app the Storage Blob Data Contributor role on the container.","Monitor for 429 throttling and back off before retrying.","Keep Azure SDK retry options enabled for transient faults.","Validate container name and base prefix configuration at startup."],"tags":["azure-blob","file-storage","exception-wrapper"],"backgroundTag":"file-write-failed","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}