EllanJiang/GameFramework · error · GameFrameworkException
Access is invalid.
Error message
Access is invalid.
What it means
Constructor guard in the private FileSystem(fullPath, access, stream): thrown when the access parameter equals FileSystemAccess.Unspecified. A file system must be opened with an explicit Read or Write access mode before any operation can be routed correctly; callers must pass a concrete FileSystemAccess value.
Solutions
- Pass FileSystemAccess.Read or FileSystemAccess.Write explicitly
- If access comes from config/settings, validate it is not Unspecified before calling
- Avoid using default(FileSystemAccess) or relying on enum zero-values for this API
- Check config parsing: an invalid enum string may silently produce the default member
Example fix
// before var fs = FileSystem.Create(path, default(FileSystemAccess), stream, ...); // after var access = FileSystemAccess.Write; // choose explicitly var fs = FileSystem.Create(path, access, stream, ...);
Defensive patterns
Strategy: validation
Validate before calling
if (access == FileSystemAccess.Unspecified) throw new ArgumentException("access must be Read or Write", nameof(access));
FileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount); Type guard
bool IsSpecifiedAccess(FileSystemAccess a) => a == FileSystemAccess.Read || a == FileSystemAccess.Write;
Try / catch
try { var fs = FileSystem.Create(path, access, stream, fc, bc); }
catch (GameFrameworkException ex) when (ex.Message == "Access is invalid.") { Log.Error($"Unspecified access for {path}"); } Prevention
- Always pass an explicit Read or Write access mode
- Never rely on default(FileSystemAccess)
- Validate enum values parsed from config before use
When it happens
Trigger: Calling FileSystem.Create or FileSystem.Open with FileSystemAccess.Unspecified as the access parameter, often the enum's default value.
Common situations: Passing default(FileSystemAccess) which equals Unspecified; deserializing an access mode from config where the value failed to map and fell back to the default enum member.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/5bb683ee80e81254.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/FileSystem/FileSystem.cs:60
private int m_StringDataOffset;
private int m_FileDataOffset;
/// <summary>
/// 初始化文件系统的新实例。
/// </summary>
/// <param name="fullPath">文件系统完整路径。</param>
/// <param name="access">文件系统访问方式。</param>
/// <param name="stream">文件系统流。</param>
private FileSystem(string fullPath, FileSystemAccess access, FileSystemStream stream)
{
if (string.IsNullOrEmpty(fullPath))
{
throw new GameFrameworkException("Full path is invalid.");
}
if (access == FileSystemAccess.Unspecified)
{
throw new GameFrameworkException("Access is invalid.");
}
if (stream == null)
{
throw new GameFrameworkException("Stream is invalid.");
}
m_FullPath = fullPath;
m_Access = access;
m_Stream = stream;
m_FileDatas = new Dictionary<string, int>(StringComparer.Ordinal);
m_BlockDatas = new List<BlockData>();
m_FreeBlockIndexes = new GameFrameworkMultiDictionary<int, int>();
m_StringDatas = new SortedDictionary<int, StringData>();
m_FreeStringIndexes = new Queue<int>();
m_FreeStringDatas = new Queue<StringData>();
m_HeaderData = default(HeaderData);View on GitHub (pinned to d0c010b051)