EllanJiang/GameFramework · error · GameFrameworkException

Can not compress with exception

Error message

Can not compress with exception '{0}'.

What it means

Utility.Compress wraps any exception thrown by the configured compression helper (e.g. ZipHelper failures) into a GameFrameworkException with this message, unless the exception is already a GameFrameworkException (which is rethrown as-is). It signals the underlying compression operation failed, not a null-argument problem.

Solutions

  1. Read the inner exception (the InnerException / formatted '{0}') to find the real failure cause thrown by the compression helper.
  2. Verify SetCompressionHelper was configured with a valid helper (e.g. Utility.Zip) and the input stream contains valid uncompressed data.
  3. Check stream positions and write permissions on the destination stream; ensure it is writable and has enough space.
  4. Wrap compression in try-catch and log the inner exception for diagnosis.

Example fix

// before
Utility.Compress(stream, compressedStream); // opaque failure
// after
try { Utility.Compress(stream, compressedStream); }
catch (GameFrameworkException e) { Log.Error("Compression failed: {0}", e.InnerException); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (stream == null || compressedStream == null) throw new ArgumentException("streams required");

Try / catch

try { Utility.Compress(stream, compressedStream); }
catch (GameFrameworkException e) { Log.Error("Compress failed: {0}", e.InnerException ?? e); }

Prevention

When it happens

Trigger: Calling any Utility.Compress overload where the helper's Compress(stream, compressedStream) throws a non-GameFrameworkException (corrupt stream, unsupported data, IO error inside the helper).

Common situations: Feeding a stream whose data the zip implementation cannot handle (e.g. already-compressed or malformed data), disk full / IO errors while writing the compressed stream, or a custom ICompressionHelper with buggy internal logic.

Related errors


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

Appendix: source

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

                }

                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>
            /// 压缩数据。
            /// </summary>
            /// <param name="stream">要压缩的数据的二进制流。</param>
            /// <returns>压缩后的数据的二进制流。</returns>
            public static byte[] Compress(Stream stream)
            {
                using (MemoryStream compressedStream = new MemoryStream())
                {
                    if (Compress(stream, compressedStream))
                    {
                        return compressedStream.ToArray();
                    }
                    else
                    {

View on GitHub (pinned to d0c010b051)