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

  1. Guard the path before calling: only invoke TryDeleteDirectoryAsync with a non-empty relative path.
  2. If the intent is to clear the container, enumerate and delete entries under the root instead of deleting the root itself.
  3. 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

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


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)