EllanJiang/GameFramework · error · GameFrameworkException
File path is invalid
Error message
File path is invalid
What it means
FileSystem.WriteFile(string name, string filePath) throws this when filePath is null or an empty string. The method reads the content of the physical file at filePath and stores it in the virtual file system; without a path there is nothing to read.
Solutions
- Pass a non-null, non-empty path to WriteFile.
- Validate/resolve the path before the call (log and abort if empty).
- Fix the configuration or default value that should supply the path.
Example fix
// before
fileSystem.WriteFile(name, config.SourcePath); // SourcePath may be empty
// after
if (!string.IsNullOrEmpty(config.SourcePath))
{
fileSystem.WriteFile(name, config.SourcePath);
} Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(filePath)) return; // or throw if (!File.Exists(filePath)) return false; // WriteFile returns false for missing files
Try / catch
try { fs.WriteFile(name, filePath); }
catch (GameFrameworkException ex) when (ex.Message == "File path is invalid") { /* fix/configure path */ } Prevention
- Validate configuration paths at startup, before any write loop runs.
- Resolve paths through one utility that rejects null/empty early.
- Distinguish 'path empty' (bug) from 'file missing' (WriteFile returns false) when handling results.
When it happens
Trigger: Calling WriteFile(name, null) or WriteFile(name, ""), typically because a config value, path-joining result, or env-derived variable was never set.
Common situations: A settings field holding the source file path is missing/empty; Path.Combine produces an empty component; a migration changed a method signature and callers pass the wrong (empty) variable.
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
- Index is invalid.
- Length is invalid.
- Length is invalid.
- Max block count is invalid.
- Max file count is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/f10ff78b7652d761.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/FileSystem/FileSystem.cs:936
m_Stream.Write(stream, length);
}
ProcessWriteFile(name, hasFile, oldBlockIndex, blockIndex, length);
m_Stream.Flush();
return true;
}
/// <summary>
/// 写入指定文件。
/// </summary>
/// <param name="name">要写入的文件名称。</param>
/// <param name="filePath">存储写入文件内容的文件路径。</param>
/// <returns>是否写入指定文件成功。</returns>
public bool WriteFile(string name, string filePath)
{
if (string.IsNullOrEmpty(filePath))
{
throw new GameFrameworkException("File path is invalid");
}
if (!File.Exists(filePath))
{
return false;
}
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return WriteFile(name, fileStream);
}
}
/// <summary>
/// 将指定文件另存为物理文件。
/// </summary>
/// <param name="name">要另存为的文件名称。</param>
/// <param name="filePath">存储写入文件内容的文件路径。</param>View on GitHub (pinned to d0c010b051)