{"record":{"id":"68bcf5bc9ffa0d79","repo":"tursodatabase/turso","slug":"writing-is-not-supported","errorCode":null,"errorMessage":"Writing is not supported.","messagePattern":"Writing is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs","lineNumber":94,"sourceCode":"            SeekOrigin.End => stream.Length + offset,\n            _ => throw new ArgumentException(Properties.Resources.InvalidEnumValue(typeof(SeekOrigin), origin), nameof(origin))\n        };\n        if (position < 0)\n            throw new IOException(Properties.Resources.SeekBeforeBegin);\n\n        stream.Position = position;\n        return position;\n    }\n\n    public override void SetLength(long value)\n    {\n        throw new NotSupportedException(Properties.Resources.ResizeNotSupported);\n    }\n\n    public override void Write(byte[] buffer, int offset, int count)\n    {\n        if (_readOnly)\n            throw new NotSupportedException(Properties.Resources.WriteNotSupported);\n\n        ValidateBuffer(buffer, offset, count);\n        if (count == 0)\n            return;\n\n        var stream = GetStream();\n        if (stream.Position + count > stream.Length)\n            throw new NotSupportedException(Properties.Resources.ResizeNotSupported);\n\n        stream.Write(buffer, offset, count);\n        Persist();\n    }\n\n    protected override void Dispose(bool disposing)\n    {\n        if (disposing && !_disposed)\n            _stream?.Dispose();\n","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs#L76-L112","documentation":"SqliteBlob constructed with readOnly: true sets _readOnly, and Write throws NotSupportedException (Properties.Resources.WriteNotSupported) before touching the buffer. This implements the stream contract for read-only streams (CanWrite == false) eagerly, so partial writes can never happen and the row is never dirtied.","triggerScenarios":"new SqliteBlob(conn, table, col, rowId, readOnly: true) followed by blob.Write(...); passing a read-only blob into generic code that writes or flushes (BinaryWriter, copying helpers with flush semantics).","commonSituations":"Opening blobs read-only in analytical/shared code paths, then reusing the same handle for a save routine; safety-minded defaults flipping readOnly on; third-party writer components handed the blob stream.","solutions":["Construct with readOnly: false (the default) when you intend to write.","Check blob.CanWrite before entering any write path.","Split read and write code paths so read-only handles can never reach writers."],"exampleFix":"// before\nusing var blob = new SqliteBlob(conn, \"files\", \"data\", rowId, readOnly: true);\nblob.Write(bytes, 0, bytes.Length); // throws: Writing is not supported\n\n// after\nusing var blob = new SqliteBlob(conn, \"files\", \"data\", rowId); // writable\nblob.Write(bytes, 0, bytes.Length);","handlingStrategy":"validation","validationCode":"if (!blob.CanWrite)\n    throw new InvalidOperationException(\"Open the blob with readOnly: false to write.\");\nblob.Write(buffer, 0, buffer.Length);","typeGuard":null,"tryCatchPattern":"try {\n    blob.Write(b, 0, b.Length);\n} catch (NotSupportedException) when (!blob.CanWrite) {\n    using var writable = new SqliteBlob(conn, table, column, rowId);\n    writable.Write(b, 0, b.Length);\n}","preventionTips":["Audit every SqliteBlob constructor call for the readOnly flag.","Branch on CanWrite before handing streams to generic writer helpers.","Keep BinaryWriter-style helpers out of read-only code paths."],"tags":["dotnet","sqlite-blob","read-only","not-supported"],"backgroundTag":"read-only-stream-write","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}