{"record":{"id":"f493d10e584c5ac7","repo":"stride3d/stride","slug":"operation-read-is-not-supported","errorCode":null,"errorMessage":"Operation 'Read' is not supported","messagePattern":"Operation 'Read' is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs","lineNumber":353,"sourceCode":"    }\n\n    /// <inheritdoc/>\n    public override long Length\n    {\n        get { return length; }\n    }\n\n    /// <inheritdoc/>\n    public override long Position\n    {\n        get { return position; }\n        set { throw NotSupported(\"SetPosition\"); }\n    }\n\n    /// <inheritdoc/>\n    public override int ReadByte()\n    {\n        if (!CanRead) throw NotSupported(\"Read\");\n\n        if (bufferOffset >= bufferLength && !AcquireNextChunk())\n            return -1; // that's just end of stream\n\n        position++;\n\n        return dataBuffer[bufferOffset++];\n    }\n\n    /// <inheritdoc/>\n    public override unsafe int Read(byte[] buffer, int offset, int count)\n    {\n        if (!CanRead) throw NotSupported(\"Read\");\n\n        var total = 0;\n\n        if (count > 0 && (buffer?.Length ?? 0) == 0)\n            throw new ArgumentOutOfRangeException(offset > 0 ? nameof(offset) : nameof(count));","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs#L335-L371","documentation":"LZ4Stream.ReadByte() first checks CanRead and throws NotSupportedException ('Read') when the stream was not opened for reading. This happens when the stream was constructed in write-only mode. Reading a byte from a write-mode LZ4 stream is invalid by design.","triggerScenarios":"Calling ReadByte() on an LZ4Stream created with FileAccess.Write / write mode, or after the stream was closed.","commonSituations":"Passing an LZ4 compression stream (write mode) to code that expects to read from it, e.g. a deserializer receiving a compressing stream instead of a decompressing one.","solutions":["Open the LZ4Stream in read mode (FileAccess.Read / LZ4StreamMode decompress) before reading","Verify CanRead before calling ReadByte and route to a different code path","Check that you did not accidentally swap the compress/decompress directions"],"exampleFix":"// before\nvar s = new LZ4Stream(fs, CompressionMode.Compress); int b = s.ReadByte();\n// after\nvar s = new LZ4Stream(fs, CompressionMode.Decompress); int b = s.CanRead ? s.ReadByte() : throw new InvalidOperationException(\"stream not readable\");","handlingStrategy":"type-guard","validationCode":"if (!lz4Stream.CanRead) throw new InvalidOperationException(\"LZ4Stream was not opened for reading; use Decompress/read mode\");","typeGuard":"static bool IsReadable(Stream s) => s is { CanRead: true };","tryCatchPattern":"try { int b = lz4Stream.ReadByte(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"'Read' is not supported\")) { throw new InvalidOperationException(\"Stream is write-mode; open LZ4Stream in read/decompress mode.\", ex); }","preventionTips":["Match stream mode to usage: Compress=>write, Decompress=>read","Check CanRead before read calls","Don't reuse disposed streams"],"tags":["csharp","stream","lz4","io"],"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"}