Code using Npgsql 7.x and Dapper works ok on net 8. But doesnt work with Npgsql 8.0.
public class Location { public NpgsqlPoint Point { get; set; } }
public async Task<IEnumerable<Location>> GetLocationsAsync(DomainParams paramObject, CancellationToken cancellationToken)
using (NpgsqlConnection conn = new(_connectionString))
{
await conn.OpenAsync(cancellationToken);
return await conn.QueryAsync<Location>("select point from locationsTable where id = ANY(@ids)) ", new { paramObject.Ids } );
} }
Error:
"Depth": 0, "HelpURL": null, "HResult": -2147467262, "ClassName": "System.InvalidCastException", "RemoteStackIndex": 0, "RemoteStackTraceString": null, "StackTraceString": " at Npgsql.Internal.AdoSerializerHelpers.g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable 1 pgTypeId, Nullable 1 npgsqlDbType, Exception inner)\n at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable 1 pgTypeId, PgSerializerOptions options, Nullable 1 npgsqlDbType)\n at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options)\n at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType)\n at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)\n at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)\n at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)\n at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 434
Later Edit: I updated the title/description to match the actual problem
It seams the problem was on the param object which although was mapped in a parent code function from a protobuf request
var paramObject = new ParamObject() { Ids = protoReq.Ids };
Now on net 8 only when using Npgsql 8.0 they would still somehow reach the initial protobuf object property 'Ids' and give this error:
at Npgsql.Internal.AdoSerializerHelpers.g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable
1 pgTypeId, Nullable
1 npgsqlDbType, Exception inner) in //src/Npgsql/Internal/AdoSerializerHelpers.cs:line 58 at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable1 pgTypeId, PgSerializerOptions options, Nullable
1 npgsqlDbType) in //src/Npgsql/Internal/AdoSerializerHelpers.cs:line 46 at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options) in //src/Npgsql/NpgsqlParameter.cs:line 565 at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType) in //src/Npgsql/NpgsqlParameterCollection.cs:line 739 at Npgsql.NpgsqlCommand.d__119.MoveNext() in //src/Npgsql/NpgsqlCommand.cs:line 1444 at Npgsql.NpgsqlCommand.d__119.MoveNext() in //src/Npgsql/NpgsqlCommand.cs:line 1596 at Npgsql.NpgsqlCommand.d__112.MoveNext() in //src/Npgsql/NpgsqlCommand.cs:line 1309 at Dapper.SqlMapper.d__33`1.MoveNext() in //Dapper/SqlMapper.Async.cs:line 434
The fix was to force a Tolist() in the mapping: var paramObject = new ParamObject(){ Ids = protoReq.Ids.ToList() };
So I still belive there is some issue in the NpgsqlParameter.ResolveTypeInfo of Npgsql 8.0 as the code works totaly fine with net 8 with Npgsql v 7.x.