I've upgraded to Npgsql 8 and started getting this:
System.InvalidOperationException: No coercion operator is defined between types 'System.IO.MemoryStream' and 'System.Nullable`1[System.Text.Json.JsonElement]'.
at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.CreateGetValueExpression(ParameterExpression dbDataReader, Int32 index, Boolean nullable, RelationalTypeMapping typeMapping, Type type, IPropertyBase property)
In Program.cs I have added:
static Program()
{
#pragma warning disable CS0618 // Type or member is obsolete
// https://www.npgsql.org/doc/release-notes/8.0.html#json-poco-and-other-dynamic-features-now-require-an-explicit-opt-in
NpgsqlConnection.GlobalTypeMapper.EnableDynamicJson();
#pragma warning restore CS0618 // Type or member is obsolete
}
But the error persists. I'll try and do a minimal reproducible example, but for now I believe it's this POCO causing grief:
public sealed class [ ...elided... ]
{
[UsedImplicitly] public Guid Id { get; init; }
public string Code { get; set; } = default!;
public JsonElement? InnerError { get; set; }
public string Message { get; set; } = default!;
public string? Target { get; set; }
}
Npgsql 7.x does not have this error.