tursodatabase/turso · error · NotSupportedException

Resizing is not supported.

Error message

Resizing is not supported.

What it means

SqliteBlob is a fixed-size snapshot of the stored BLOB (a MemoryStream sized to the value read at construction). SetLength is deliberately unsupported (NotSupportedException, Properties.Resources.ResizeNotSupported): the provider has no incremental blob API to grow or shrink the column value, and a resized in-memory buffer would desynchronize from the row.

Solutions

  1. To change the blob's size, write the full new byte[] with an UPDATE statement against the row.
  2. To clear/truncate, UPDATE the column to a zero-length blob.
  3. If you need growable buffering, accumulate in a local MemoryStream and write the final value back once via SQL.

Example fix

// before
blob.SetLength(blob.Length + 64); // throws: Resizing is not supported

// after: resize by rewriting the whole value
byte[] grown = new byte[blob.Length + 64];
blob.Seek(0, SeekOrigin.Begin);
blob.Read(grown, 0, (int)blob.Length);
using var cmd = conn.CreateCommand();
cmd.CommandText = "UPDATE files SET data = $d WHERE rowid = $id";
cmd.Parameters.AddWithValue("$d", grown);
cmd.Parameters.AddWithValue("$id", rowId);
cmd.ExecuteNonQuery();
Defensive patterns

Strategy: fallback

Validate before calling

// SqliteBlob never supports resize; detect the intent up front
if (desiredLength != blob.Length) {
    // route through SQL: rewrite the whole column value (see exampleFix)
} else {
    blob.Write(buffer, offset, count); // in-place overwrite only
}

Try / catch

try {
    blob.SetLength(n);
} catch (NotSupportedException) {
    // fixed-size blob: rewrite the whole value with an UPDATE instead
}

Prevention

When it happens

Trigger: Calling blob.SetLength(n) directly; using components that resize streams internally (BinaryWriter-style writers, some serializer/compression streams that call SetLength).

Common situations: Copy-pasting FileStream truncation idioms (SetLength(0) to clear a file) onto a database blob; wrapping the blob in a writer that assumes resize support; expecting sqlite3_blob-like semantics when the provider is whole-value based.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/a9b8225f3ee242b5. Report an issue: GitHub.

Appendix: source

Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs:88

    {
        var stream = GetStream();
        var position = origin switch
        {
            SeekOrigin.Begin => offset,
            SeekOrigin.Current => stream.Position + offset,
            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();
    }

View on GitHub (pinned to 244cde92a7)