On one of my projects we are using MassTransit to interact with RabbitMQ. After upgrading to MassTransit 8, we noticed that some of our integration tests started to fail.
Here is the specific message contract that was causing the issue:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface GenerateDocumentsCommand | |
{ | |
Uri TemplateUri { get; } | |
IEnumerable<(string FileName,byte[] Data)> Data { get; } | |
} |
Notice the tuple type I’m using in the data contract? That is the culprit of this issue. With the upgrade to MassTransit 8, the default serializer has switched from Newtonsoft.Json to System.Text.Json. And although for most Newtonsoft.Json features an equivalent exists in System.Text.Json, this is not the case for everything.
I solved the issue by switching from a ValueTuple to a record type:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface GenerateDocumentsCommand | |
{ | |
Uri TemplateUri { get; } | |
IEnumerable<Document> Data { get; } | |
} | |
public record Document(string Filename, byte[] Data); |
Fixed it!
More information
MassTransit–.NET 8 upgrade warnings
Migrate from Newtonsoft.Json to System.Text.Json - .NET | Microsoft Learn