{"record":{"id":"3ed6cc0809b9114c","repo":"dotnet/orleans","slug":"this-stream-is-read-only","errorCode":null,"errorMessage":"This stream is read-only.","messagePattern":"This stream is read-only\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"src/Azure/Orleans.Journaling.AzureStorage/ReadOnlySequenceStream.cs","lineNumber":85,"sourceCode":"        return new ValueTask<int>(Read(buffer.Span));\n    }\n\n    public override long Seek(long offset, SeekOrigin origin)\n    {\n        ObjectDisposedException.ThrowIf(_disposed, this);\n        var newPosition = origin switch\n        {\n            SeekOrigin.Begin => offset,\n            SeekOrigin.Current => _position + offset,\n            SeekOrigin.End => _sequence.Length + offset,\n            _ => throw new ArgumentOutOfRangeException(nameof(origin))\n        };\n\n        Position = newPosition;\n        return _position;\n    }\n\n    public override void SetLength(long value) => throw new NotSupportedException(\"This stream is read-only.\");\n\n    public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(\"This stream is read-only.\");\n\n    public override void Write(ReadOnlySpan<byte> buffer) => throw new NotSupportedException(\"This stream is read-only.\");\n\n    protected override void Dispose(bool disposing)\n    {\n        _disposed = true;\n        base.Dispose(disposing);\n    }\n}\n","sourceCodeStart":67,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Orleans.Journaling.AzureStorage/ReadOnlySequenceStream.cs#L67-L97","documentation":"Thrown by ReadOnlySequenceStream.SetLength because the stream wraps a fixed ReadOnlySequence<byte> and is read-only; changing the length is meaningless and unsupported. The stream exposes CanWrite = false, so callers should respect that capability flag.","triggerScenarios":"Calling stream.SetLength(...) on a ReadOnlySequenceStream, typically via a generic serializer or stream utility that unconditionally calls SetLength when preparing a buffer.","commonSituations":"A third-party serializer/deserializer that calls SetLength to pre-size; code written for MemoryStream reused against this read-only stream; copy helpers that truncate before writing.","solutions":["Check stream.CanWrite before calling SetLength; skip for read-only streams.","Use a MemoryStream or PipeWriter for write paths instead of ReadOnlySequenceStream.","Refactor the consumer to branch on CanWrite/CanSeek capabilities."],"exampleFix":"// before\nstream.SetLength(needed);\n// after\nif (stream.CanWrite) stream.SetLength(needed);","handlingStrategy":"type-guard","validationCode":"if (stream.CanWrite) stream.SetLength(value);","typeGuard":"static bool IsWritableStream(Stream s) => s.CanWrite;","tryCatchPattern":null,"preventionTips":["Check CanWrite before SetLength/Write.","Use MemoryStream or PipeWriter for write paths.","Keep read-only and writable stream types distinct."],"tags":["azure-blob-storage","journaling","stream","not-supported","read-only"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}