stride3d/stride · error · NotSupportedException
Operation 'SetPosition' is not supported
Error message
Operation 'SetPosition' is not supported
What it means
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.
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
Example fix
// before lz4Stream.Position = 0; // after if (lz4Stream.CanSeek) lz4Stream.Position = 0; else lz4Stream = new LZ4Stream(new MemoryStream(rawData), mode);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!stream.CanSeek) throw new InvalidOperationException("Position assignment requires a seekable stream; this LZ4 stream is sequential"); Type guard
static bool SupportsPositionSet(Stream s) => s.CanSeek;
Try / catch
try { lz4Stream.Position = 0; }
catch (NotSupportedException) { // non-seekable: recreate stream instead
lz4Stream.Dispose(); lz4Stream = new LZ4Stream(new MemoryStream(rawData), CompressionMode.Decompress); } Prevention
- Never assign Position on LZ4Stream; it is forward-only
- Check CanSeek before any seek/position code
- Treat LZ4 streams as sequential pipelines in abstractions
When it happens
Trigger: Assigning to stream.Position on an LZ4Stream, e.g. `lz4Stream.Position = 0;`, or any API internally that sets Position to rewind the stream.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Operation 'Read' is not supported
- Operation 'Seek' is not supported
- Operation 'SetLength' is not supported
- Operation 'Write' is not supported
- Unexpected end of stream
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/61a539b11237f5b9.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Serialization/Serialization/LZ4/LZ4Stream.cs:347
}
/// <inheritdoc/>
public override void Flush()
{
if (bufferOffset > 0 && CanWrite) FlushCurrentChunk();
}
/// <inheritdoc/>
public override long Length
{
get { return length; }
}
/// <inheritdoc/>
public override long Position
{
get { return position; }
set { throw NotSupported("SetPosition"); }
}
/// <inheritdoc/>
public override int ReadByte()
{
if (!CanRead) throw NotSupported("Read");
if (bufferOffset >= bufferLength && !AcquireNextChunk())
return -1; // that's just end of stream
position++;
return dataBuffer[bufferOffset++];
}
/// <inheritdoc/>
public override unsafe int Read(byte[] buffer, int offset, int count)
{View on GitHub (pinned to 96fad776d2)