{"record":{"id":"d7a240f275250c65","repo":"stride3d/stride","slug":"operation-setlength-is-not-supported","errorCode":null,"errorMessage":"Operation 'SetLength' is not supported","messagePattern":"Operation 'SetLength' is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs","lineNumber":460,"sourceCode":"            innerStream.Seek(-innerStreamPosition, SeekOrigin.Current);\n            Reset();\n        }\n        else if (newPosition == Position)\n        {\n            // nothing to do\n        }\n        else\n        {\n            throw NotSupported(\"Seek\");\n        }\n\n        return Position;\n    }\n\n    /// <inheritdoc/>\n    public override void SetLength(long value)\n    {\n        throw NotSupported(\"SetLength\");\n    }\n\n    /// <inheritdoc/>\n    public override void WriteByte(byte value)\n    {\n        if (!CanWrite) throw NotSupported(\"Write\");\n\n        position++;\n\n        if (dataBuffer == null)\n        {\n            dataBuffer = new byte[blockSize];\n            bufferLength = blockSize;\n            bufferOffset = 0;\n        }\n\n        if (bufferOffset >= bufferLength)\n        {","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs#L442-L478","documentation":"LZ4Stream.SetLength is unconditionally unsupported: the size of the underlying compressed data is determined by writing and flushing blocks, and there is no way to pre-truncate or extend an LZ4 stream. Any call throws NotSupportedException ('SetLength') immediately.","triggerScenarios":"Calling SetLength directly, or indirectly via APIs like FileStream-style truncation helpers, or framework code that calls SetLength before writing.","commonSituations":"Reusable temp-file handling code that truncates via SetLength before rewriting; generically-written compression wrapper code that assumes SetLength exists.","solutions":["Remove SetLength calls; recreate a fresh LZ4Stream over a truncated/inner reset stream instead","Guard with `if (stream.CanWrite && stream.CanSeek)` style checks or try SetLength only on seekable plain streams","Reopen the underlying stream with FileMode.Truncate before constructing the LZ4Stream"],"exampleFix":"// before\nlz4.SetLength(0);\n// after\ninnerStream.SetLength(0); innerStream.Seek(0, SeekOrigin.Begin); lz4 = new LZ4Stream(innerStream, CompressionMode.Compress);","handlingStrategy":"try-catch","validationCode":"if (stream is LZ4Stream) throw new InvalidOperationException(\"SetLength is not supported on LZ4Stream; truncate the inner stream instead\");","typeGuard":null,"tryCatchPattern":"try { lz4.SetLength(0); }\ncatch (NotSupportedException) { // truncate underlying stream and recreate\n  lz4.Dispose(); innerStream.SetLength(0); innerStream.Seek(0, SeekOrigin.Begin); lz4 = new LZ4Stream(innerStream, CompressionMode.Compress); }","preventionTips":["Never pre-truncate compressed streams with SetLength","Recreate the LZ4Stream after truncating the inner stream","Guard generic truncation helpers with CanSeek checks"],"tags":["csharp","stream","lz4"],"backgroundTag":"operation-not-supported","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}