{"record":{"id":"062c55a744c883ec","repo":"tursodatabase/turso","slug":"parameter-value-is-not-a-tursoparameter","errorCode":null,"errorMessage":"Parameter {value} is not a TursoParameter","messagePattern":"Parameter (.+?) is not a TursoParameter","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoParameterCollection.cs","lineNumber":114,"sourceCode":"\n        _parameters.RemoveAt(index);\n    }\n\n    protected override DbParameter GetParameter(int index)\n    {\n        return _parameters[index];\n    }\n\n    protected override DbParameter GetParameter(string parameterName)\n    {\n        return _parameters.Find(p => p.ParameterName == parameterName)\n               ?? throw new ArgumentException($\"Parameter {parameterName} not found\");\n    }\n\n    protected override void SetParameter(int index, DbParameter value)\n    {\n        _parameters[index] = value as TursoParameter\n                             ?? throw new ArgumentException($\"Parameter {value} is not a TursoParameter\");\n    }\n\n    protected override void SetParameter(string parameterName, DbParameter value)\n    {\n        var index = IndexOf(parameterName);\n        if (index == -1)\n            throw new ArgumentException($\"Parameter {parameterName} not found\");\n        _parameters[index] = value as TursoParameter\n                             ?? throw new ArgumentException($\"Parameter {value} is not a TursoParameter\");\n    }\n}\n","sourceCodeStart":96,"sourceCodeEnd":126,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data/TursoParameterCollection.cs#L96-L126","documentation":"TursoParameterCollection.SetParameter(int index, DbParameter value) backs the integer indexer setter and throws this ArgumentException when the value is not a TursoParameter ('value as TursoParameter' yields null). The collection is strongly typed by design; it never wraps or converts foreign DbParameter types.","triggerScenarios":"Assigning cmd.Parameters[0] = new SqlParameter(...) / new SqliteParameter(...) / any custom DbParameter subclass; passing a DbParameter-typed variable that actually holds another provider's type; generic factory code parameterized on DbProviderFactory reusing parameter objects across providers.","commonSituations":"Multi-provider code that creates parameters with one factory and assigns them to another provider's command; refactoring from SqlClient where collections sometimes accepted conversions; helper libraries storing parameters as DbParameter.","solutions":["Create the replacement with new TursoParameter(...) before assigning it to the indexer.","In provider-agnostic code, build parameters via cmd.CreateParameter() so the type always matches the collection.","Copy Name/Value/DbType from the foreign parameter into a fresh TursoParameter instead of assigning it directly."],"exampleFix":"// before\ncmd.Parameters[0] = new SqlParameter(\"@id\", 42);\n\n// after\ncmd.Parameters[0] = new TursoParameter(\"@id\", 42);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsTursoParam(DbParameter p) => p is TursoParameter;","tryCatchPattern":null,"preventionTips":["In provider-agnostic code create parameters with cmd.CreateParameter().","Copy name/value into a new TursoParameter instead of assigning foreign DbParameter objects."],"tags":["csharp","dotnet","parameters","collection","type-mismatch"],"backgroundTag":"parameter-type-mismatch","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}