Problem with MassTransit deserialization
See original GitHub issueOkay so I have a problem with using MassTransit and it’s deserialization.
We’re publishing messages into a specific queue with RabbitMQ, which should then be further processed by our background services using MassTransit.
The string coming in through the queue looks as following
{
"routingKey": "article.put",
"responseQueue": {
"exchange": "testexchange_gateway",
"responseRoutingKey": "gatewayResponseQueue",
"vhost": "testvhost"
},
"deviceProperties": {
"deviceType": "DESKTOP",
"deviceSize": {
"width": 10,
"height": 10
},
"javascriptEnabled": false
},
"action": "PUT",
"transactionId": "62b6174d-04b7-4937-b617-4d04b70937b0",
"contentType": "application/json",
"body": "Testmessage published while running"
}
With the Contract looking like
public interface IMessage
{
string routingKey { get; set; }
ResponseQueue responseQueue { get; set; }
DeviceProperties deviceProperties { get; set; }
string action { get; set; }
string transactionId { get; set; }
string contentType { get; set; }
string body { get; set; }
}
public interface ResponseQueue
{
string exchange { get; set; }
string responseRoutingKey { get; set; }
string vhost { get; set; }
}
public interface DeviceProperties
{
string deviceType { get; set; }
DeviceSize deviceSize { get; set; }
bool javascriptEnabled { get; set; }
}
public interface DeviceSize
{
int width { get; set; }
int height { get; set; }
}
My problem now is, whenever I want to consume that message using MassTransit, I will get an error in my _error queue:
MT-Fault-ExceptionType: | System.ArgumentNullException
-- | --
Value cannot be null. Parameter name: source
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at MassTransit.Serialization.JsonConsumeContext..ctor(JsonSerializer deserializer, IObjectTypeDeserializer objectTypeDeserializer, ReceiveContext receiveContext, MessageEnvelope envelope) at MassTransit.Serialization.JsonMessageDeserializer.MassTransit.IMessageDeserializer.Deserialize(ReceiveContext receiveContext)
which I don’t quite understand, as all values needed should be right there.
My consumer:
class ArticleGetConsumer : IConsumer<IMessage>
{
public Task Consume(ConsumeContext<IMessage> context)
{
var routingKey = context.Message.routingKey;
return Task.FromResult(0);
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Problem with MassTransit deserialization - 2 · Issue #1707
I am having the same issue as here I am trying to receive the message from rabbitmq were other application pushes data.
Read more >How to avoid incompatible during deserializing ...
When using the request/response pattern, during the deserialization of the response, an incompatibility error occurs. Apparently, the publisher ...
Read more >Handling a message produced by MassTransit
MessageDeserializationException : An error occurred while attempting to extract logical messages from incoming physical message ...
Read more >Message Serialization
To interoperate with other languages and platforms, message structure is important. MassTransit encapsulates messages in an envelope before they are serialized.
Read more >JSON Serilization configuration issue.
I am trying to configure the serializerd on Mass Transit to make sure it ... JsonSerializationException: Cannot deserialize the current JSON ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Should look like this:
Sounds like you need to use the RawJsonMessageDeserializer.
Covered in this video.