{"record":{"id":"6a3f8367f0e7c698","repo":"stride3d/stride","slug":"operation-seek-is-not-supported","errorCode":null,"errorMessage":"Operation 'Seek' is not supported","messagePattern":"Operation 'Seek' is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs","lineNumber":437,"sourceCode":"            }\n            else\n            {\n                if (!AcquireNextChunk()) break;\n            }\n        }\n        position += total;\n\n        return total;\n    }\n\n    /// <inheritdoc/>\n    public override long Seek(long offset, SeekOrigin origin)\n    {\n        var newPosition = origin switch\n        {\n            SeekOrigin.Begin => offset,\n            SeekOrigin.Current => Position + offset,\n            SeekOrigin.End => throw NotSupported(\"Seek\"),\n            _ => throw new ArgumentOutOfRangeException(nameof(origin)),\n        };\n        if (newPosition == 0)\n        {\n            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    }","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs#L419-L455","documentation":"LZ4Stream.Seek supports only a narrow set of repositionings: it can seek to position 0 (rewind to the start of the compressed data, resetting decompression state), stay at the current position, or use SeekOrigin.Begin/Current offsets that resolve to those cases. SeekOrigin.End and any other target position throw NotSupportedException ('Seek'), because arbitrary seeking in an LZ4 block stream would require decompressing everything up to that point.","triggerScenarios":"Calling Seek(offset, SeekOrigin.End); calling Seek to a nonzero destination other than the current position; library code that assumes seekable streams (e.g. serializers doing backtracking).","commonSituations":"Deserializers seeking back to fix up lengths; code using SeekOrigin.End to compute stream length; random-access reads over LZ4-compressed data.","solutions":["Restructure to sequential forward reads only","To rewind, call Seek(0, SeekOrigin.Begin) which is supported (resets the stream)","If random access is required, decompress into a MemoryStream or file first and seek on that","Use SeekOrigin.Current with positive offsets only when the result equals current position or 0"],"exampleFix":"// before\nlz4.Seek(0, SeekOrigin.End);\n// after\nlz4.Seek(0, SeekOrigin.Begin); // supported rewind; or decompress fully then seek on the plain stream","handlingStrategy":"try-catch","validationCode":"if (origin == SeekOrigin.End) throw new InvalidOperationException(\"SeekOrigin.End is never supported on LZ4Stream\");\nif (!(offset == 0 || seekTarget == stream.Position)) throw new InvalidOperationException(\"LZ4Stream supports only rewind-to-0 and no-op seeks\");","typeGuard":"static bool IsSeekableTarget(long newPosition, long current) => newPosition == 0 || newPosition == current;","tryCatchPattern":"try { lz4.Seek(offset, origin); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"'Seek' is not supported\")) { // fallback: decompress fully, then seek on plain stream\n  var ms = new MemoryStream(); lz4.CopyTo(ms); ms.Position = 0; ms.Seek(offset, origin); }","preventionTips":["Only Seek(0, SeekOrigin.Begin) or no-op seeks on LZ4Stream","Decompress to memory/file when random access is required","Check CanSeek before generically wrapping streams"],"tags":["csharp","stream","lz4","seek"],"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"}