{"record":{"id":"0c5187bf648835f5","repo":"EllanJiang/GameFramework","slug":"file-system-is-not-readable","errorCode":null,"errorMessage":"File system is not readable.","messagePattern":"File system is not readable\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":336,"sourceCode":"        {\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new GameFrameworkException(\"Name is invalid.\");\n            }\n\n            return m_FileDatas.ContainsKey(name);\n        }\n\n        /// <summary>\n        /// 读取指定文件。\n        /// </summary>\n        /// <param name=\"name\">要读取的文件名称。</param>\n        /// <returns>存储读取文件内容的二进制流。</returns>\n        public byte[] ReadFile(string name)\n        {\n            if (m_Access != FileSystemAccess.Read && m_Access != FileSystemAccess.ReadWrite)\n            {\n                throw new GameFrameworkException(\"File system is not readable.\");\n            }\n\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new GameFrameworkException(\"Name is invalid.\");\n            }\n\n            FileInfo fileInfo = GetFileInfo(name);\n            if (!fileInfo.IsValid)\n            {\n                return null;\n            }\n\n            int length = fileInfo.Length;\n            byte[] buffer = new byte[length];\n            if (length > 0)\n            {\n                m_Stream.Position = fileInfo.Offset;","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L318-L354","documentation":"ReadFile(string) returns the bytes of a stored file, but only if the FileSystem was opened with read access. The library throws GameFrameworkException(\"File system is not readable.\") when m_Access is Write-only, because the underlying stream was not opened for reading. Open the file system with FileSystemAccess.Read or ReadWrite to read files.","triggerScenarios":"Calling ReadFile on a FileSystem created/opened with FileSystemAccess.Write (write-only).","commonSituations":"Opening a file system for writing packed files in a build pipeline and later reusing the same instance to read them; copy-pasting open code with the wrong access flag; a resource component configured with Write access while game code calls read APIs.","solutions":["Open/create the file system with FileSystemAccess.Read or FileSystemAccess.ReadWrite instead of Write.","Check fileSystem.Access before reading, or use a separate instance opened for reading.","Restructure code so write-phase and read-phase use distinct file system instances."],"exampleFix":"// before\nFileSystem fs = fileSystemManager.CreateFileSystem(path, FileSystemAccess.Write, ...);\nbyte[] data = fs.ReadFile(name); // throws\n// after\nFileSystem fs = fileSystemManager.CreateFileSystem(path, FileSystemAccess.ReadWrite, ...);\nbyte[] data = fs.ReadFile(name);","handlingStrategy":"validation","validationCode":"if (fileSystem.Access == FileSystemAccess.Read || fileSystem.Access == FileSystemAccess.ReadWrite) { var data = fileSystem.ReadFile(name); }","typeGuard":"bool IsReadable(FileSystem fs) => fs.Access == FileSystemAccess.Read || fs.Access == FileSystemAccess.ReadWrite;","tryCatchPattern":"try { data = fileSystem.ReadFile(name); } catch (GameFrameworkException ex) { Log.Error(\"File system not readable: {0}\", ex.Message); }","preventionTips":["Choose the FileSystemAccess flag matching all operations you plan to perform.","Prefer ReadWrite when unsure.","Open separate instances for write-only build steps."],"tags":["csharp","filesystem","access-violation"],"backgroundTag":"unsupported-operation","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}