{"record":{"id":"42990b670cfe5416","repo":"tursodatabase/turso","slug":"only-direct-remote-and-embedded-replica-turso-conn","errorCode":null,"errorMessage":"Only direct remote and embedded replica Turso connections can be wrapped.","messagePattern":"Only direct remote and embedded replica Turso connections can be wrapped\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs","lineNumber":50,"sourceCode":"    private bool _extensionsEnabled;\n    private readonly List<(string File, string? Proc)> _pendingExtensions = [];\n\n    public SqliteConnection()\n    {\n    }\n\n    public SqliteConnection(string? connectionString)\n    {\n        ConnectionString = connectionString;\n    }\n\n    public SqliteConnection(TursoConnection connection, bool ownsConnection)\n    {\n        ArgumentNullException.ThrowIfNull(connection);\n        var options = new SqliteConnectionStringBuilder(connection.ConnectionString);\n        if (options.IsLocal)\n        {\n            throw new ArgumentException(\n                \"Only direct remote and embedded replica Turso connections can be wrapped.\",\n                nameof(connection));\n        }\n\n        _connectionOptions = options;\n        _managedConnection = connection;\n        _ownsManagedConnection = ownsConnection;\n        _wrapsManagedConnection = true;\n        _readOnly = options.Mode == SqliteOpenMode.ReadOnly;\n    }\n\n    [AllowNull]\n    public override string ConnectionString\n    {\n        get => _connectionOptions.ConnectionString;\n        set\n        {\n            if (State == ConnectionState.Open)","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs#L32-L68","documentation":"This ArgumentException is thrown by the SqliteConnection(TursoConnection, bool) constructor when the supplied TursoConnection is a local database connection. Only direct remote and embedded replica Turso connections expose the managed backend that the wrapper relies on.","triggerScenarios":"Calling new SqliteConnection(tursoConnection, ownsConnection: true) where tursoConnection's connection string resolves to a local file (options.IsLocal is true), e.g. a connection opened with a plain file path.","commonSituations":"Mixing up local and remote TursoConnection objects when refactoring code from the native SQLite path to the managed facade; dynamically choosing connection targets and passing a local one to the wrapper by mistake.","solutions":["Wrap only TursoConnection instances opened as direct remote or embedded replica connections","For local databases, use the regular SqliteConnection(connectionString) native path instead of the TursoConnection wrapper","Check the TursoConnection.ConnectionString with SqliteConnectionStringBuilder and verify IsLocal is false before constructing the wrapper"],"exampleFix":"// before\nvar turso = new TursoConnection(\"file:local.db\");\nvar wrapper = new SqliteConnection(turso, ownsConnection: true); // throws\n\n// after\nvar turso = new TursoConnection(\"libsql://my-db.turso.io\");\nvar wrapper = new SqliteConnection(turso, ownsConnection: true);","handlingStrategy":"validation","validationCode":"if (new SqliteConnectionStringBuilder(tursoConn.ConnectionString).IsLocal)\n    return new SqliteConnection(tursoConn.ConnectionString); // native path instead","typeGuard":"bool Wrappable(TursoConnection c) => !new SqliteConnectionStringBuilder(c.ConnectionString).IsLocal;","tryCatchPattern":"try { return new SqliteConnection(tursoConn, true); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"embedded replica\"))\n{\n    return new SqliteConnection(tursoConn.ConnectionString);\n}","preventionTips":["Decide local vs remote once in a factory and pick the right wrapper"],"tags":["dotnet","connection","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-09-06T07:15:26.990Z","contentChangedAt":"2026-09-06T07:15:26.990Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}