EllanJiang/GameFramework · error · GameFrameworkException
Directory name is invalid.
Error message
Directory name is invalid.
What it means
Utility.Path.RemoveEmptyDirectory throws when the directoryName argument is null or empty. A null/empty path can never name a directory, and Directory operations on it would fail ambiguously, so the library fails fast with GameFrameworkException. Note the method throws rather than returning false for this case.
Solutions
- Pass a valid, non-empty directory path; check string.IsNullOrEmpty before calling.
- Fix the config/loading code that produced the empty directory name.
- If the directory may legitimately be absent, check Directory.Exists first and skip the call.
Example fix
// before
string dir = settings.GetValue("CacheDir"); // may be null
Utility.Path.RemoveEmptyDirectory(dir);
// after
string dir = settings.GetValue("CacheDir");
if (!string.IsNullOrEmpty(dir) && Directory.Exists(dir))
Utility.Path.RemoveEmptyDirectory(dir); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(directoryName))
throw new ArgumentException("Directory name must be non-empty", nameof(directoryName));
bool ok = Utility.Path.RemoveEmptyDirectory(directoryName); Type guard
bool IsValidDirectory(string path) => !string.IsNullOrEmpty(path);
Try / catch
try
{
Utility.Path.RemoveEmptyDirectory(dir);
}
catch (GameFrameworkException ex) when (ex.Message == "Directory name is invalid.")
{
// config missing; log and use default directory
} Prevention
- Validate directory-name config values at startup, before cleanup jobs run.
- Use Path.Combine and check the result is non-empty before use.
- Prefer explicit fallback default paths over uninitialized settings.
When it happens
Trigger: Calling Utility.Path.RemoveEmptyDirectory(null) or RemoveEmptyDirectory("") — e.g. a configured directory name that failed to load from settings, or a joined path that came out empty.
Common situations: Config files where a cleanup-directory key is missing; Path.Combine results that collapsed to empty; iterating a list of directories where one entry was never initialized.
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
- Resource pack path is invalid.
- Apply resources complete callback is invalid.
- Asset is invalid.
- Asset name is invalid.
- Check resources complete callback is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/38c74d5a201455b4.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Utility/Utility.Path.cs:59
string regularPath = GetRegularPath(path);
if (regularPath == null)
{
return null;
}
return regularPath.Contains("://") ? regularPath : ("file:///" + regularPath).Replace("file:////", "file:///");
}
/// <summary>
/// 移除空文件夹。
/// </summary>
/// <param name="directoryName">要处理的文件夹名称。</param>
/// <returns>是否移除空文件夹成功。</returns>
public static bool RemoveEmptyDirectory(string directoryName)
{
if (string.IsNullOrEmpty(directoryName))
{
throw new GameFrameworkException("Directory name is invalid.");
}
try
{
if (!Directory.Exists(directoryName))
{
return false;
}
// 不使用 SearchOption.AllDirectories,以便于在可能产生异常的环境下删除尽可能多的目录
string[] subDirectoryNames = Directory.GetDirectories(directoryName, "*");
int subDirectoryCount = subDirectoryNames.Length;
foreach (string subDirectoryName in subDirectoryNames)
{
if (RemoveEmptyDirectory(subDirectoryName))
{
subDirectoryCount--;
}View on GitHub (pinned to d0c010b051)