Dictionary<string,object> does not seem to be deserialized properly

Hello I am publishing and event that contains a Dictionary<string,object>

It does not seem to be properly deserialized by NServiceBus. This only seems to happen when the message is of type Event

"FieldAnswers": {
    "Id": {
      "$type": "System.Text.Json.JsonElement, System.Text.Json",
      "ValueKind": 3
    },
    "MerchantId": {
      "$type": "System.Text.Json.JsonElement, System.Text.Json",
      "ValueKind": 3
    },

@mauroservienti

For this to work you need to set TypeNameHandling to All, Auto or Objects

See https://docs.particular.net/nservicebus/serialization/newtonsoft#usage-custom-settings for more details on how to customize the settings.

Does this help?

I verified that this work by modifying the https://docs.particular.net/samples/serializers/newtonsoft/ sample, can you see if you can modify it to reproduce your issue? (Send or Publish operations have no effect on the deserialization)

let me try it… but that is not working for me…

So I have an event of type Record.

It is deserialized properly but I do publish it is then when the content is different

This is what ends up in the queue:

“FieldAnswers”: {
“Id”: {
“$type”: “System.Text.Json.JsonElement, System.Text.Json”,
“ValueKind”: 0
},
“Name”: {
“$type”: “System.Text.Json.JsonElement, System.Text.Json”,
“ValueKind”: 0
},
“MobileNumber”: {
“$type”: “System.Text.Json.JsonElement, System.Text.Json”,
“ValueKind”: 0
}
}

This is my settings:

var settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
Formatting = Formatting.Indented,
Converters =
{
new IsoDateTimeConverter
{
DateTimeStyles = DateTimeStyles.RoundtripKind
}
}
};

var serialization = endpointConfiguration.UseSerialization();
serialization.Settings(settings);

added the mutator

Log message

 {
        "Id": "a6674d37-ff4b-4b1e-9b84-2c808c95cbe1",
        "Type": "MobileDeviceSnapshot",
        "FieldAnswers": {
          "Id": {
            "$type": "System.Text.Json.JsonElement, System.Text.Json",
            "ValueKind": 3
          },
          "Name": {
            "$type": "System.Text.Json.JsonElement, System.Text.Json",
            "ValueKind": 3
          },
          "MobileNumber": {
            "$type": "System.Text.Json.JsonElement, System.Text.Json",
            "ValueKind": 3
          }
        }
      }

I’ve verified that the sample works with record types as well.

public record CreateOrder :
    IMessage
{
    public Dictionary<string,object> MyProperty { get; set; }
}

can you confirm that it work for you?

Since its the publish that fails could it be that there is some assembly mismatch between you publisher and the subscriber? (check that the subscriber have the correct version of the event loaded)

When looking at my payload I see

{
  "$type": "CreateOrder, Sample",
  "MyProperty": {
    "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib",
    "1": {
      "$type": "OrderItem, Sample",
      "ItemId": 0,
      "Quantity": 5
    }
  }
}

but looking at your it seems like it get serialized with System.Text.Json types in there, that seem off?

Are you able to create a minimal reproduction of the issue and share it with us?

Both publisher and subscriber are using the same assembly…

This stuff was working when all the contracts were classes… right now contracts are using record type…
But it is funny because I have an apigateway that sends a command with the same structure and that works.

I am having a issue with a publisher

How about a zoom debug session?

Any luck… This is a blocker…

There’s no support SLA associated with the public forum.

If production is impacted you might want to open a support case to ensure it’s treated with a higher priority. Support cases can be raised at https://particular.net/support.

When you raise the case please attach the message contract record, endpoint configuration, csproj file etc so that we can take a deeper look