Skip to content

Serialisation problem with duplicated jsonb field after upgrading to marten 8 #3997

@TCBroad

Description

@TCBroad

Hi,

After updating to v8, we've found a problem writing rows with duplicated jsonb fields.

Here's a partial stack trace that shows the problem:

System.InvalidCastException
Writing values of 'Symprex.Signature365.Common.Data.ExternalReferences' is not supported for parameters having NpgsqlDbType 'Jsonb'.
   at Npgsql.Internal.AdoSerializerHelpers.<GetTypeInfoForWriting>g__ThrowWritingNotSupported|1_0(Type type, PgSerializerOptions options, Nullable`1 pgTypeId, Nullable`1 npgsqlDbType, Exception inner)
   at Npgsql.Internal.AdoSerializerHelpers.GetTypeInfoForWriting(Type type, Nullable`1 pgTypeId, PgSerializerOptions options, Nullable`1 npgsqlDbType)
   at Npgsql.NpgsqlParameter.ResolveTypeInfo(PgSerializerOptions options)
   at Npgsql.NpgsqlParameterCollection.ProcessParameters(PgSerializerOptions options, Boolean validateValues, CommandType commandType)
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token) in /_/src/Marten/Internal/Sessions/AutoClosingLifetime.cs:line 305
   at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex) in /_/src/JasperFx/Core/Exceptions/IExceptionTransform.cs:line 174
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token) in /_/src/Marten/Internal/Sessions/AutoClosingLifetime.cs:line 331
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token) in /_/src/Marten/Internal/Sessions/AutoClosingLifetime.cs:line 368
   at Marten.Internal.Sessions.AutoClosingLifetime.ExecuteBatchPagesAsync(IReadOnlyList`1 pages, List`1 exceptions, CancellationToken token) in /_/src/Marten/Internal/Sessions/AutoClosingLifetime.cs:line 368
   at Polly.ResiliencePipeline.<>c__2`1.<<ExecuteAsync>b__2_0>d.MoveNext()
--- End of stack trace from previous location ---
   at Polly.Outcome`1.GetResultOrRethrow()
   at Polly.ResiliencePipeline.ExecuteAsync[TState](Func`3 callback, TState state, CancellationToken cancellationToken)
   at Marten.Internal.Sessions.DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token) in /_/src/Marten/Internal/Sessions/DocumentSessionBase.SaveChanges.cs:line 130
   at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex) in /_/src/JasperFx/Core/Exceptions/IExceptionTransform.cs:line 174
   at Marten.Internal.Sessions.DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token) in /_/src/Marten/Internal/Sessions/DocumentSessionBase.SaveChanges.cs:line 137
   at Marten.Internal.Sessions.DocumentSessionBase.ExecuteBatchAsync(IUpdateBatch batch, CancellationToken token) in /_/src/Marten/Internal/Sessions/DocumentSessionBase.SaveChanges.cs:line 154
   at Marten.Internal.Sessions.DocumentSessionBase.SaveChangesAsync(CancellationToken token) in /_/src/Marten/Internal/Sessions/DocumentSessionBase.SaveChanges.cs:line 58

We are using the Newtonsoft package and have the following line in our container setup:

NpgsqlTypeMapper.Mappings[NpgsqlDbType.Jsonb] = new NpgsqlTypeMapping(NpgsqlDbType.Jsonb, DbType.Object, "jsonb", typeof(ExternalReferences));

This code was all fine with an older version of Marten. Any ideas what we can do to get past this issue?

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