EllanJiang/GameFramework · error · GameFrameworkException

Stream is not readable.

Error message

Stream is not readable.

What it means

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.

Solutions

  1. Reopen the source with read access, e.g. new FileStream(path, FileMode.Open, FileAccess.Read).
  2. If you only have a write-only stream, first copy the data into a MemoryStream (which is readable) and pass that.
  3. Assert stream.CanRead before calling WriteFile to fail with a clearer message at the call site.

Example fix

// before
using (var fsStream = new FileStream(path, FileMode.Open, FileAccess.Write))
{
    fileSystem.WriteFile(name, fsStream); // throws: not readable
}
// after
using (var fsStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
    fileSystem.WriteFile(name, fsStream);
}
Defensive patterns

Strategy: validation

Validate before calling

if (stream == null || !stream.CanRead)
    throw new ArgumentException("A readable stream is required.", nameof(stream));

Try / catch

try { fs.WriteFile(name, stream); }
catch (GameFrameworkException ex) when (ex.Message == "Stream is not readable.") { /* reopen source with FileAccess.Read */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/980a8273cd25db26. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/FileSystem/FileSystem.cs:893

            if (string.IsNullOrEmpty(name))
            {
                throw new GameFrameworkException("Name is invalid.");
            }

            if (name.Length > byte.MaxValue)
            {
                throw new GameFrameworkException(Utility.Text.Format("Name '{0}' is too long.", name));
            }

            if (stream == null)
            {
                throw new GameFrameworkException("Stream is invalid.");
            }

            if (!stream.CanRead)
            {
                throw new GameFrameworkException("Stream is not readable.");
            }

            bool hasFile = false;
            int oldBlockIndex = -1;
            if (m_FileDatas.TryGetValue(name, out oldBlockIndex))
            {
                hasFile = true;
            }

            if (!hasFile && m_FileDatas.Count >= m_HeaderData.MaxFileCount)
            {
                return false;
            }

            int length = (int)(stream.Length - stream.Position);
            int blockIndex = AllocBlock(length);
            if (blockIndex < 0)
            {

View on GitHub (pinned to d0c010b051)