tursodatabase/turso · error · NotSupportedException
Writing is not supported.
Error message
Writing is not supported.
What it means
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.
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.
Example fix
// before using var blob = new SqliteBlob(conn, "files", "data", rowId, readOnly: true); blob.Write(bytes, 0, bytes.Length); // throws: Writing is not supported // after using var blob = new SqliteBlob(conn, "files", "data", rowId); // writable blob.Write(bytes, 0, bytes.Length);
Defensive patterns
Strategy: validation
Validate before calling
if (!blob.CanWrite)
throw new InvalidOperationException("Open the blob with readOnly: false to write.");
blob.Write(buffer, 0, buffer.Length); Try / catch
try {
blob.Write(b, 0, b.Length);
} catch (NotSupportedException) when (!blob.CanWrite) {
using var writable = new SqliteBlob(conn, table, column, rowId);
writable.Write(b, 0, b.Length);
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20).
Data as JSON: /api/errors/68bcf5bc9ffa0d79.
Report an issue: GitHub.
Appendix: source
Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs:94
SeekOrigin.End => stream.Length + offset,
_ => throw new ArgumentException(Properties.Resources.InvalidEnumValue(typeof(SeekOrigin), origin), nameof(origin))
};
if (position < 0)
throw new IOException(Properties.Resources.SeekBeforeBegin);
stream.Position = position;
return position;
}
public override void SetLength(long value)
{
throw new NotSupportedException(Properties.Resources.ResizeNotSupported);
}
public override void Write(byte[] buffer, int offset, int count)
{
if (_readOnly)
throw new NotSupportedException(Properties.Resources.WriteNotSupported);
ValidateBuffer(buffer, offset, count);
if (count == 0)
return;
var stream = GetStream();
if (stream.Position + count > stream.Length)
throw new NotSupportedException(Properties.Resources.ResizeNotSupported);
stream.Write(buffer, offset, count);
Persist();
}
protected override void Dispose(bool disposing)
{
if (disposing && !_disposed)
_stream?.Dispose();
View on GitHub (pinned to 244cde92a7)