{"record":{"id":"61a539b11237f5b9","repo":"stride3d/stride","slug":"operation-setposition-is-not-supported","errorCode":null,"errorMessage":"Operation 'SetPosition' is not supported","messagePattern":"Operation 'SetPosition' is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs","lineNumber":347,"sourceCode":"    }\n\n    /// <inheritdoc/>\n    public override void Flush()\n    {\n        if (bufferOffset > 0 && CanWrite) FlushCurrentChunk();\n    }\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    {","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs#L329-L365","documentation":"LZ4Stream is a sequential (non-seekable) compression stream, so assigning its Position property is not a meaningful operation and throws NotSupportedException with operation name 'SetPosition'. Seeking backwards would require decompressing from the start; the stream simply does not support it.","triggerScenarios":"Assigning to stream.Position on an LZ4Stream, e.g. `lz4Stream.Position = 0;`, or any API internally that sets Position to rewind the stream.","commonSituations":"Copying code that works on FileStream/MemoryStream (where Position assignment rewinds) onto an LZ4-wrapped stream; deserialization code that tries to seek back to re-read a header.","solutions":["Do not assign Position on LZ4Stream; restructure the code to read strictly forward","If rewind is needed, close and recreate the LZ4Stream over a fresh copy of the underlying stream","Check stream.CanSeek before seeking and take a non-seekable code path"],"exampleFix":"// before\nlz4Stream.Position = 0;\n// after\nif (lz4Stream.CanSeek) lz4Stream.Position = 0; else lz4Stream = new LZ4Stream(new MemoryStream(rawData), mode);","handlingStrategy":"type-guard","validationCode":"if (!stream.CanSeek) throw new InvalidOperationException(\"Position assignment requires a seekable stream; this LZ4 stream is sequential\");","typeGuard":"static bool SupportsPositionSet(Stream s) => s.CanSeek;","tryCatchPattern":"try { lz4Stream.Position = 0; }\ncatch (NotSupportedException) { // non-seekable: recreate stream instead\n  lz4Stream.Dispose(); lz4Stream = new LZ4Stream(new MemoryStream(rawData), CompressionMode.Decompress); }","preventionTips":["Never assign Position on LZ4Stream; it is forward-only","Check CanSeek before any seek/position code","Treat LZ4 streams as sequential pipelines in abstractions"],"tags":["csharp","stream","lz4","compression"],"backgroundTag":"unsupported-operation","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"}