{"record":{"id":"0e1dba879bb64633","repo":"OrchardCMS/OrchardCore","slug":"cannot-delete-the-root-directory","errorCode":null,"errorMessage":"Cannot delete the root directory.","messagePattern":"Cannot delete the root directory\\.","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs","lineNumber":487,"sourceCode":"            return await blob.DeleteIfExistsAsync();\n        }\n        catch (Exception ex)\n        {\n            throw new FileStoreException($\"Cannot delete file '{path}'.\", ex);\n        }\n    }\n\n    public async Task<bool> TryDeleteDirectoryAsync(string path)\n    {\n        await EnsureCapabilitiesAsync();\n\n        if (_capabilities?.HasHierarchicalNamespace == true)\n        {\n            try\n            {\n                if (string.IsNullOrEmpty(path))\n                {\n                    throw new FileStoreException(\"Cannot delete the root directory.\");\n                }\n\n                var prefix = this.Combine(_basePrefix, path);\n                var directoryClient = _dataLakeFileSystemClient.GetDirectoryClient(prefix);\n\n                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)","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs#L469-L505","documentation":"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.","triggerScenarios":"Calling IFileStore.TryDeleteDirectoryAsync(\"\") or TryDeleteDirectoryAsync(null) on a store configured with a hierarchical namespace enabled.","commonSituations":"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.","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."],"exampleFix":"// before\nawait _fileStore.TryDeleteDirectoryAsync(folderPath);\n// after\nif (!string.IsNullOrEmpty(folderPath))\n{\n    await _fileStore.TryDeleteDirectoryAsync(folderPath);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path)) throw new ArgumentException(\"A non-empty directory path is required.\", nameof(path));\nawait _fileStore.TryDeleteDirectoryAsync(path);","typeGuard":"bool canDelete(string path) => !string.IsNullOrEmpty(path);","tryCatchPattern":null,"preventionTips":["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."],"tags":["azure-blob","file-storage","argument-validation"],"backgroundTag":"empty-required-field","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"}