clockworklabs/SpacetimeDB · error · InvalidOperationException

Unknown compression type

Error message

Unknown compression type

What it means

DecompressDecodeMessage reads the first byte of a server message as a CompressionAlgos tag and switches on it to pick a decompressor. This error is a generic guard thrown by the switch's discard arm when that tag byte is not None, Brotli, or Gzip — i.e. the byte stream is not a message produced by a compatible server (corrupted, truncated, or from a newer protocol version introducing an unrecognized compression algorithm).

Solutions

  1. Verify the client SDK version and server version are compatible; an unrecognized compression algorithm usually means a protocol version mismatch.
  2. Check that the byte array passed to DecompressDecodeMessage is a complete, uncorrupted server message and not offset by extra bytes.
  3. If the server is intentionally sending a new compression algorithm, upgrade the SpacetimeDB C# SDK to a version that supports it.
  4. Wrap the message decode path in a try-catch for InvalidOperationException and resynchronize the connection rather than crashing the client.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at sdks/csharp/src/CompressionHelpers.cs:64 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of clockworklabs/SpacetimeDB@fdd647dfac (2026-09-13). Data as JSON: /api/errors/df2ec2e262befd07. Report an issue: GitHub.

Appendix: source

Thrown at sdks/csharp/src/CompressionHelpers.cs:68

internal static ServerMessage DecompressDecodeMessage(byte[] bytes)
{
    using var stream = new MemoryStream(bytes);

    // The stream will never be empty. It will at least contain the compression algo.
    var compression = (CompressionAlgos)stream.ReadByte();

    if (compression == CompressionAlgos.None)
    {
        return new ServerMessage.BSATN().Read(new BinaryReader(stream));
    }

    Stream decompressedStream = compression switch
    {
        CompressionAlgos.Brotli => BrotliReader(stream),
        CompressionAlgos.Gzip => GzipReader(stream),
        _ => throw new InvalidOperationException("Unknown compression type"),
    };

    // TODO: consider pooling these.
    // DO NOT TRY TO TAKE THIS OUT. The BrotliStream ReadByte() implementation allocates an array
    // PER BYTE READ. You have to do it all at once to avoid that problem.
    using (decompressedStream)
    using (MemoryStream memoryStream = new MemoryStream())
    {
        decompressedStream.CopyTo(memoryStream);
        memoryStream.Seek(0, SeekOrigin.Begin);
        return new ServerMessage.BSATN().Read(new BinaryReader(memoryStream));
    }
}

View on GitHub (pinned to fdd647dfac)