OrchardCMS/OrchardCore · error · FileStoreException
Cannot delete the root directory.
Error message
Cannot delete the root directory.
What it means
Thrown by TryDeleteDirectoryAsync in the Azure Blob FileStore when a delete of a directory (blob prefix) with an empty path is requested while the storage account uses a hierarchical namespace (ADLS Gen2). The root of the container cannot be deleted as a directory, so the library fails fast with a FileStoreException instead of issuing a doomed Data Lake call.
Solutions
- Guard the path before calling: only invoke TryDeleteDirectoryAsync with a non-empty relative path.
- If the intent is to clear the container, enumerate and delete entries under the root instead of deleting the root itself.
- Fix the configuration/setting that produced the empty path.
Example fix
// before
await _fileStore.TryDeleteDirectoryAsync(folderPath);
// after
if (!string.IsNullOrEmpty(folderPath))
{
await _fileStore.TryDeleteDirectoryAsync(folderPath);
} Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(path)) throw new ArgumentException("A non-empty directory path is required.", nameof(path));
await _fileStore.TryDeleteDirectoryAsync(path); Type guard
bool canDelete(string path) => !string.IsNullOrEmpty(path);
Prevention
- Never pass empty or null paths to directory APIs; resolve against a configured base folder.
- Centralize path construction in one helper that rejects empty segments.
- Treat 'clear all' as an explicit operation on child entries, not a root delete.
When it happens
Trigger: Calling IFileStore.TryDeleteDirectoryAsync("") or TryDeleteDirectoryAsync(null) on a store configured with a hierarchical namespace enabled.
Common situations: Computed paths built by joining empty segments; media/caching code that derives a subfolder from settings that were never configured, yielding an empty path; callers trying to 'clear' the whole container.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- The values for and must not be the same.
- The values for and must not be the same.
- Cannot delete directory
- Cannot move file ' ' to ' '.
- Cannot copy file ' ' because it does not exist.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/0e1dba879bb64633.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:487
return await blob.DeleteIfExistsAsync();
}
catch (Exception ex)
{
throw new FileStoreException($"Cannot delete file '{path}'.", ex);
}
}
public async Task<bool> TryDeleteDirectoryAsync(string path)
{
await EnsureCapabilitiesAsync();
if (_capabilities?.HasHierarchicalNamespace == true)
{
try
{
if (string.IsNullOrEmpty(path))
{
throw new FileStoreException("Cannot delete the root directory.");
}
var prefix = this.Combine(_basePrefix, path);
var directoryClient = _dataLakeFileSystemClient.GetDirectoryClient(prefix);
if (!await directoryClient.ExistsAsync())
{
return false;
}
await directoryClient.DeleteAsync(recursive: true);
return true;
}
catch (FileStoreException)
{
throw;
}
catch (RequestFailedException ex) when (ex.Status == 404)View on GitHub (pinned to 4306c0717f)