OrchardCMS/OrchardCore · error · FileStoreException
Cannot delete directory
Error message
Cannot delete directory '{path}'. What it means
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.
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.
Example fix
// before
await _fileStore.TryDeleteDirectoryAsync(path);
// after
try
{
await _fileStore.TryDeleteDirectoryAsync(path);
}
catch (FileStoreException ex)
{
_logger.LogError(ex.InnerException, "Failed to delete directory {Path}", path);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (await _fileStore.DirectoryExistsAsync(path))
{
await _fileStore.TryDeleteDirectoryAsync(path);
} Try / catch
try
{
await _fileStore.TryDeleteDirectoryAsync(path);
}
catch (FileStoreException ex)
{
var azureError = ex.InnerException as RequestFailedException;
_logger.LogError(ex, "Delete failed for {Path} (status {Status})", path, azureError?.Status);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Cannot delete the root directory.
- Cannot move file ' ' to ' '.
- The values for and must not be the same.
- Cannot copy file ' ' because it does not exist.
- Cannot copy file ' ' because a file already exists in the…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/d829a265f30c33ff.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:511
if (!await directoryClient.ExistsAsync())
{
return false;
}
await directoryClient.DeleteAsync(recursive: true);
return true;
}
catch (FileStoreException)
{
throw;
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
return false;
}
catch (Exception ex)
{
throw new FileStoreException($"Cannot delete directory '{path}'.", ex);
}
}
try
{
if (string.IsNullOrEmpty(path))
{
throw new FileStoreException("Cannot delete the root directory.");
}
var blobsWereDeleted = false;
var prefix = this.Combine(_basePrefix, path);
prefix = NormalizePrefix(prefix);
var page = _blobContainer.GetBlobsAsync(BlobTraits.Metadata, BlobStates.None, prefix, CancellationToken.None);
await foreach (var blob in page)
{
var blobReference = _blobContainer.GetBlobClient(blob.Name);View on GitHub (pinned to 4306c0717f)