{"record":{"id":"a9b8225f3ee242b5","repo":"tursodatabase/turso","slug":"resizing-is-not-supported","errorCode":null,"errorMessage":"Resizing is not supported.","messagePattern":"Resizing is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs","lineNumber":88,"sourceCode":"    {\n        var stream = GetStream();\n        var position = origin switch\n        {\n            SeekOrigin.Begin => offset,\n            SeekOrigin.Current => stream.Position + offset,\n            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    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data.Sqlite/SqliteBlob.cs#L70-L106","documentation":"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.","triggerScenarios":"Calling blob.SetLength(n) directly; using components that resize streams internally (BinaryWriter-style writers, some serializer/compression streams that call SetLength).","commonSituations":"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.","solutions":["To change the blob's size, write the full new byte[] with an UPDATE statement against the row.","To clear/truncate, UPDATE the column to a zero-length blob.","If you need growable buffering, accumulate in a local MemoryStream and write the final value back once via SQL."],"exampleFix":"// before\nblob.SetLength(blob.Length + 64); // throws: Resizing is not supported\n\n// after: resize by rewriting the whole value\nbyte[] grown = new byte[blob.Length + 64];\nblob.Seek(0, SeekOrigin.Begin);\nblob.Read(grown, 0, (int)blob.Length);\nusing var cmd = conn.CreateCommand();\ncmd.CommandText = \"UPDATE files SET data = $d WHERE rowid = $id\";\ncmd.Parameters.AddWithValue(\"$d\", grown);\ncmd.Parameters.AddWithValue(\"$id\", rowId);\ncmd.ExecuteNonQuery();","handlingStrategy":"fallback","validationCode":"// SqliteBlob never supports resize; detect the intent up front\nif (desiredLength != blob.Length) {\n    // route through SQL: rewrite the whole column value (see exampleFix)\n} else {\n    blob.Write(buffer, offset, count); // in-place overwrite only\n}","typeGuard":null,"tryCatchPattern":"try {\n    blob.SetLength(n);\n} catch (NotSupportedException) {\n    // fixed-size blob: rewrite the whole value with an UPDATE instead\n}","preventionTips":["Treat SqliteBlob as read / overwrite-in-place only, sized to the stored value.","Do all sizing work in a local MemoryStream and persist once via SQL.","Provide a repo-level UpdateBlob helper so callers never reach for SetLength."],"tags":["dotnet","sqlite-blob","not-supported","stream"],"backgroundTag":"unsupported-stream-operation","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"}