{"record":{"id":"df2ec2e262befd07","repo":"clockworklabs/SpacetimeDB","slug":"unknown-compression-type","errorCode":null,"errorMessage":"Unknown compression type","messagePattern":"Unknown compression type","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sdks/csharp/src/CompressionHelpers.cs","lineNumber":68,"sourceCode":"internal static ServerMessage DecompressDecodeMessage(byte[] bytes)\n{\n    using var stream = new MemoryStream(bytes);\n\n    // The stream will never be empty. It will at least contain the compression algo.\n    var compression = (CompressionAlgos)stream.ReadByte();\n\n    if (compression == CompressionAlgos.None)\n    {\n        return new ServerMessage.BSATN().Read(new BinaryReader(stream));\n    }\n\n    Stream decompressedStream = compression switch\n    {\n        CompressionAlgos.Brotli => BrotliReader(stream),\n        CompressionAlgos.Gzip => GzipReader(stream),\n        _ => throw new InvalidOperationException(\"Unknown compression type\"),\n    };\n\n    // TODO: consider pooling these.\n    // DO NOT TRY TO TAKE THIS OUT. The BrotliStream ReadByte() implementation allocates an array\n    // PER BYTE READ. You have to do it all at once to avoid that problem.\n    using (decompressedStream)\n    using (MemoryStream memoryStream = new MemoryStream())\n    {\n        decompressedStream.CopyTo(memoryStream);\n        memoryStream.Seek(0, SeekOrigin.Begin);\n        return new ServerMessage.BSATN().Read(new BinaryReader(memoryStream));\n    }\n}","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/fdd647dfac506d0967cc4492e9fce380706c94cb/sdks/csharp/src/CompressionHelpers.cs#L50-L86","documentation":"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).","triggerScenarios":"Thrown at sdks/csharp/src/CompressionHelpers.cs:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the client SDK version and server version are compatible; an unrecognized compression algorithm usually means a protocol version mismatch.","Check that the byte array passed to DecompressDecodeMessage is a complete, uncorrupted server message and not offset by extra bytes.","If the server is intentionally sending a new compression algorithm, upgrade the SpacetimeDB C# SDK to a version that supports it.","Wrap the message decode path in a try-catch for InvalidOperationException and resynchronize the connection rather than crashing the client."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fdd647dfac506d0967cc4492e9fce380706c94cb","analyzedAt":"2026-09-13T15:42:39.379Z","contentChangedAt":"2026-09-13T15:42:39.379Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}