EllanJiang/GameFramework · error · GameFrameworkException
Name is invalid.
Error message
Name is invalid.
What it means
GetFileInfo looks up a file entry by its exact name in the filesystem's internal dictionary and requires a non-empty name to perform the lookup. An empty or null name cannot match any entry, so it is rejected before the dictionary access.
Solutions
- Ensure the name passed is the exact non-empty string used when the file was added to the filesystem
- Guard the caller with string.IsNullOrEmpty before calling GetFileInfo
- Check where the name originates (config, user input) and validate/populate it earlier
- Remember lookups are exact and case-sensitive (StringComparer.Ordinal) — verify the name matches the stored one
Example fix
// before
var info = fileSystem.GetFileInfo(fileName); // fileName may be ""
// after
if (string.IsNullOrEmpty(fileName)) return default(FileInfo);
var info = fileSystem.GetFileInfo(fileName);
if (info.Name == null) { /* file not found handling */ } Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(name)) throw new ArgumentException("name is required", nameof(name));
var info = fileSystem.GetFileInfo(name); Type guard
bool IsValidFileName(string n) => !string.IsNullOrEmpty(n);
Try / catch
try { var info = fileSystem.GetFileInfo(name); }
catch (GameFrameworkException ex) when (ex.Message == "Name is invalid.") { Log.Error("GetFileInfo called with empty name — check the name source"); } Prevention
- Validate the name at its source (config, user input) before filesystem calls
- Remember lookups are exact and case-sensitive (ordinal) — reuse the same name constant used at AddFile time
- Check default(FileInfo) return for not-found names instead of expecting an exception
When it happens
Trigger: Calling fileSystem.GetFileInfo(null) or GetFileInfo(""). Note: a valid but non-existent name does NOT throw — it returns default(FileInfo); only null/empty throws.
Common situations: A file name variable sourced from user input, a save slot, or a config field that was never populated; string operations that produced an empty name (e.g. Path.GetFileName on a directory-only path).
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Offset is invalid.
- Length is invalid.
- Max file count is invalid.
- Max block count is invalid.
- Stream is not writable.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/1d0423ba539c0d1f.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/FileSystem/FileSystem.cs:263
m_StringDatas.Clear();
m_FreeStringIndexes.Clear();
m_FreeStringDatas.Clear();
m_BlockDataOffset = 0;
m_StringDataOffset = 0;
m_FileDataOffset = 0;
}
/// <summary>
/// 获取文件信息。
/// </summary>
/// <param name="name">要获取文件信息的文件名称。</param>
/// <returns>获取的文件信息。</returns>
public FileInfo GetFileInfo(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new GameFrameworkException("Name is invalid.");
}
int blockIndex = 0;
if (!m_FileDatas.TryGetValue(name, out blockIndex))
{
return default(FileInfo);
}
BlockData blockData = m_BlockDatas[blockIndex];
return new FileInfo(name, GetClusterOffset(blockData.ClusterIndex), blockData.Length);
}
/// <summary>
/// 获取所有文件信息。
/// </summary>
/// <returns>获取的所有文件信息。</returns>
public FileInfo[] GetAllFileInfos()
{View on GitHub (pinned to d0c010b051)