EllanJiang/GameFramework · error · GameFrameworkException

Compressed stream is invalid.

Error message

Compressed stream is invalid.

What it means

Guard in CompressionHelper.Compress: thrown when the compressedStream argument is null. After validating the helper and the input bytes/offset/length, compression needs a destination stream to write into; a null stream means there is nowhere to put the compressed output, so the call fails fast.

Solutions

  1. Create/open the destination stream before compressing (e.g. new MemoryStream())
  2. Check that any stream-opening code succeeded and was not disposed early
  3. Validate stream != null at the call site

Example fix

// before
Stream stream = OpenOutputFile(); // may return null
Utility.Compression.Compress(data, 0, data.Length, stream);
// after
using (Stream stream = File.Create(path))
{
    Utility.Compression.Compress(data, 0, data.Length, stream);
}
Defensive patterns

Strategy: validation

Validate before calling

if (compressedStream == null) throw new ArgumentNullException(nameof(compressedStream));

Type guard

bool HasDestination(Stream compressedStream) => compressedStream != null && compressedStream.CanWrite;

Try / catch

try { Utility.Compression.Compress(bytes, 0, bytes.Length, stream); } catch (GameFrameworkException ex) { Log.Error("Compression stream invalid: " + ex.Message); }

Prevention

When it happens

Trigger: Calling Compress(bytes, offset, length, null); passing a stream variable that failed to open or was disposed/nulled earlier.

Common situations: File.Open failing upstream and the stream variable staying null; disposing a stream before compression; forgetting to create a MemoryStream wrapper.

Related errors


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

Appendix: source

Thrown at GameFramework/Utility/Utility.Compression.cs:111

            {
                if (s_CompressionHelper == null)
                {
                    throw new GameFrameworkException("Compressed helper is invalid.");
                }

                if (bytes == null)
                {
                    throw new GameFrameworkException("Bytes is invalid.");
                }

                if (offset < 0 || length < 0 || offset + length > bytes.Length)
                {
                    throw new GameFrameworkException("Offset or length is invalid.");
                }

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

                try
                {
                    return s_CompressionHelper.Compress(bytes, offset, length, compressedStream);
                }
                catch (Exception exception)
                {
                    if (exception is GameFrameworkException)
                    {
                        throw;
                    }

                    throw new GameFrameworkException(Text.Format("Can not compress with exception '{0}'.", exception), exception);
                }
            }

            /// <summary>

View on GitHub (pinned to d0c010b051)