ArgumentOutOfRangeException in Firebird ADO Client dll when trying to insert string longer than 4000 characters
I'm getting this exception whenever I try to to Execute() any query with a string parameter that's longer than 4000 characters. Dapper is apparently passing -1 to the FbParameter class Size property setter and that is causing it to crash.
I've had to manually create the FbCommand and add the parameters for any query that uses fields of that size or higher. Is there any way to create the FbParameter manually when passing the created params object to Execute() or do I have to create the FbCommand manually every time until this can get fixed?
Do you have a stack trace from when it crashes? Depending on when that happens will impact how easy it is to fix.
I had a similar problem with Oracle, but I solved with a custom query parameter, see the issue DapperLib/Dapper#142
Here's a stack trace. The issue is easily reproducible on my end. It happens any time I try to insert more than 4000 characters in a VARCHAR or BLOB field in a Firebird database.
at FirebirdSql.Data.FirebirdClient.FbParameter.set_Size(Int32 value) in C:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbParameter.cs:line 81
at ParamInfo1b5dc6b3-3e2f-4373-aea9-b1d6d89d47a1(IDbCommand , Object )
at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action2 paramReader) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 191 at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 3395
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1346
at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable1 commandType) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1221
Ah, that's good! The nice thing about that stack-trace is that the error happens in the .Size assignment. We can probably hack around that with some kind of fallback strategy. Cheers.
@mgravell I see this issue is open since 2016. Now we have december 2020, and I ran into this error. The reason is that the Size property in the FbParameter is tried to fill with a negative (!) value. The Stack Trace is:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
at FirebirdSql.Data.FirebirdClient.FbParameter.set_Size(Int32 value)
at ParamInfo1f81b3e6-0b6b-4f9b-a614-6bfde8837abe(IDbCommand , Object )
at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action`2 paramReader)
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action`2 paramReader)
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command)
at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType)
at FbAdapter.Insert(IDbConnection connection, IDbTransaction transaction, Nullable`1 commandTimeout, String tableName, String columnList, String parameterList, IEnumerable`1 keyProperties, Object entityToInsert)
at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable`1 commandTimeout)
Is it possible to find a 'hack around' as you mentioned? I created many classes, building on Dapper/Dapper.Contrib. When thie error cannot be fixed I must invest days to find a solution around, probably without Dapper when inserting/updating.
Greetings from Norway!
BR Heiko.