EllanJiang/GameFramework · error · GameFrameworkException

Access is invalid.

Error message

Access is invalid.

What it means

CreateFileSystem requires an explicit FileSystemAccess mode. FileSystemAccess.Unspecified is only valid when opening/reading metadata, not for creating a new file system, so passing it throws 'Access is invalid.'

Solutions

  1. Pass FileSystemAccess.ReadWrite (or Write) explicitly to CreateFileSystem.
  2. Fix the source of the access variable — ensure it is set, not default(Unspecified).
  3. If access depends on context, resolve it to a concrete value before creating.

Example fix

// before
var fs = fileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.Unspecified, 16, 1024); // throws
// after
var fs = fileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.ReadWrite, 16, 1024);
Defensive patterns

Strategy: validation

Validate before calling

if (access == FileSystemAccess.Unspecified)
    access = FileSystemAccess.ReadWrite; // or reject before calling CreateFileSystem

Type guard

static bool IsExplicitAccess(FileSystemAccess access) => access == FileSystemAccess.Read || access == FileSystemAccess.Write || access == FileSystemAccess.ReadWrite;

Try / catch

try { fileSystemManager.CreateFileSystem(fullPath, access, maxFileCount, maxBlockCount); }
catch (GameFrameworkException ex) when (ex.Message == "Access is invalid.") { /* substitute a concrete access mode and retry */ }

Prevention

When it happens

Trigger: Calling FileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.Unspecified, maxFileCount, maxBlockCount).

Common situations: Access mode stored in an uninitialized enum field (default value is Unspecified for the first enum member), or code copied from an Open call where Unspecified was meant to infer access from an existing file.

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/d68d621f4016ffe5. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/FileSystem/FileSystemManager.cs:151

        /// <param name="access">要创建的文件系统的访问方式。</param>
        /// <param name="maxFileCount">要创建的文件系统的最大文件数量。</param>
        /// <param name="maxBlockCount">要创建的文件系统的最大块数据数量。</param>
        /// <returns>创建的文件系统。</returns>
        public IFileSystem CreateFileSystem(string fullPath, FileSystemAccess access, int maxFileCount, int maxBlockCount)
        {
            if (m_FileSystemHelper == null)
            {
                throw new GameFrameworkException("File system helper is invalid.");
            }

            if (string.IsNullOrEmpty(fullPath))
            {
                throw new GameFrameworkException("Full path is invalid.");
            }

            if (access == FileSystemAccess.Unspecified)
            {
                throw new GameFrameworkException("Access is invalid.");
            }

            if (access == FileSystemAccess.Read)
            {
                throw new GameFrameworkException("Access read is invalid.");
            }

            fullPath = Utility.Path.GetRegularPath(fullPath);
            if (m_FileSystems.ContainsKey(fullPath))
            {
                throw new GameFrameworkException(Utility.Text.Format("File system '{0}' is already exist.", fullPath));
            }

            FileSystemStream fileSystemStream = m_FileSystemHelper.CreateFileSystemStream(fullPath, access, true);
            if (fileSystemStream == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Create file system stream for '{0}' failure.", fullPath));
            }

View on GitHub (pinned to d0c010b051)