Sitelet https://github.com/DapperLib/Dapper/issues/2049
Skip to content

Bug/Regression doing a query with a jsonb column as string with 2.1.* #2049

Description

@lucax88x

Ciao!

I've reproduced the issue there:

https://github.com/lucax88x/dapper-bug

So, if you have a postgresql db, and you use a jsonb column, and you use netwonsoft as deserializer such as:

NpgsqlConnection.GlobalTypeMapper.UseJsonNet(settings: settings);

and perform a a query like

 await conn.QueryFirstOrDefaultAsync<string>("select \"Content\" from public.\"Posts\"");

will throw an exception with

 ---> System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Dapper.SqlMapper.GetValue[T](DbDataReader reader, Type effectiveType, Object val) in /_/Dapper/SqlMapper.cs:line 1366
   --- End of inner exception stack trace ---
   at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in /_/Dapper/SqlMapper.cs:line 3928
   at Dapper.SqlMapper.QueryRowAsync[T](IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 496

This happens only with 2.1.*, if I revert to 2.0.151 everything works perfectly.

This is probably the PR that breaks it.

ps: without json.net it also work perfectly, it's just a combination of json.net and jsonb.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions