{"record":{"id":"980a8273cd25db26","repo":"EllanJiang/GameFramework","slug":"stream-is-not-readable","errorCode":null,"errorMessage":"Stream is not readable.","messagePattern":"Stream is not readable\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":893,"sourceCode":"\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new GameFrameworkException(\"Name is invalid.\");\n            }\n\n            if (name.Length > byte.MaxValue)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Name '{0}' is too long.\", name));\n            }\n\n            if (stream == null)\n            {\n                throw new GameFrameworkException(\"Stream is invalid.\");\n            }\n\n            if (!stream.CanRead)\n            {\n                throw new GameFrameworkException(\"Stream is not readable.\");\n            }\n\n            bool hasFile = false;\n            int oldBlockIndex = -1;\n            if (m_FileDatas.TryGetValue(name, out oldBlockIndex))\n            {\n                hasFile = true;\n            }\n\n            if (!hasFile && m_FileDatas.Count >= m_HeaderData.MaxFileCount)\n            {\n                return false;\n            }\n\n            int length = (int)(stream.Length - stream.Position);\n            int blockIndex = AllocBlock(length);\n            if (blockIndex < 0)\n            {","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L875-L911","documentation":"FileSystem.WriteFile(string name, Stream stream) throws this when the supplied stream cannot be read (stream.CanRead is false). Even though the method is called \"WriteFile\" (writing INTO the file system), it reads the content from the given stream, so a write-only stream is unusable.","triggerScenarios":"Passing a stream opened with FileAccess.Write (no read access), a write-only network/upload stream, or a MemoryStream created from a buffer the caller wrapped in a write-only wrapper into WriteFile.","commonSituations":"Opening a FileStream with FileMode.OpenOrCreate / FileAccess.Write and then handing it to WriteFile; passing the request stream of an HTTP upload; confusion between the direction of the copy (stream -> file system).","solutions":["Reopen the source with read access, e.g. new FileStream(path, FileMode.Open, FileAccess.Read).","If you only have a write-only stream, first copy the data into a MemoryStream (which is readable) and pass that.","Assert stream.CanRead before calling WriteFile to fail with a clearer message at the call site."],"exampleFix":"// before\nusing (var fsStream = new FileStream(path, FileMode.Open, FileAccess.Write))\n{\n    fileSystem.WriteFile(name, fsStream); // throws: not readable\n}\n// after\nusing (var fsStream = new FileStream(path, FileMode.Open, FileAccess.Read))\n{\n    fileSystem.WriteFile(name, fsStream);\n}","handlingStrategy":"validation","validationCode":"if (stream == null || !stream.CanRead)\n    throw new ArgumentException(\"A readable stream is required.\", nameof(stream));","typeGuard":null,"tryCatchPattern":"try { fs.WriteFile(name, stream); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Stream is not readable.\") { /* reopen source with FileAccess.Read */ }","preventionTips":["Remember WriteFile copies FROM the stream; always open sources with FileAccess.Read.","Assert stream.CanRead at helper boundaries before forwarding to the file system.","If only a write-only stream exists, buffer through a MemoryStream first."],"tags":["gameframework","filesystem","stream","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}