EllanJiang/GameFramework · error · GameFrameworkException

Stream is invalid.

Error message

Stream is invalid.

What it means

Constructor guard in the private FileSystem(fullPath, access, stream): thrown when the stream argument is null. After validating fullPath and access, the constructor requires a live underlying FileSystemStream to read or write file-system data; a null stream means the caller failed to open the underlying file.

Solutions

  1. Check the stream creation result for null before passing it to Create/Open
  2. Ensure the archive file exists or is creatable at fullPath (directory present, permissions OK)
  3. Make the stream factory throw or log instead of silently returning null
  4. Use File access APIs that throw on failure to get a real error message about why the stream is missing

Example fix

// before
var stream = File.Open(fullPath); // returns null on failure
var fs = FileSystem.Create(fullPath, access, stream, ...); // throws here
// after
var stream = File.Open(fullPath);
if (stream == null) throw new InvalidOperationException("Failed to open " + fullPath);
var fs = FileSystem.Create(fullPath, access, stream, ...);
Defensive patterns

Strategy: type-guard

Validate before calling

if (stream == null) throw new ArgumentNullException(nameof(stream));
FileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount);

Type guard

bool HasValidStream(FileSystemStream s) => s != null;

Try / catch

try { var fs = FileSystem.Create(path, access, stream, fc, bc); }
catch (GameFrameworkException ex) when (ex.Message == "Stream is invalid.") { Log.Error("Stream creation failed earlier — check the open call's null return"); }

Prevention

When it happens

Trigger: Calling FileSystem.Create or FileSystem.Open with a null stream — typically the result of a failed File.Open/stream factory call whose null return was not checked.

Common situations: File.Open returning null on missing file or permission error (GameFramework-style APIs often return null instead of throwing); a custom FileSystemStream implementation factory returning null on failure.

Related errors


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

Appendix: source

Thrown at GameFramework/FileSystem/FileSystem.cs:65

        /// </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);
            m_BlockDataOffset = 0;
            m_StringDataOffset = 0;
            m_FileDataOffset = 0;

            Utility.Marshal.EnsureCachedHGlobalSize(CachedBytesLength);

View on GitHub (pinned to d0c010b051)