Hi
Our microservices use NServiceBus SQL Server persistence and AWS SQS & SNS Topics for the message subscriptions. All event messages published by a microservice inherit from an abstract base class: BaseEvent
I have recently upgraded from NServiceBus.Newtonsoft.Json 2.3.0
to 2.4.0
.
I also use the following code to explicitly specify the TypeNameHandling.None
in the JsonSerializerSettings
for the NewtonsoftJsonSerializer
(although I understand that in 2.4.0 the serializer by default uses TypeNameHandling.None
)
this.UseSerialization<NewtonsoftJsonSerializer>()
.Settings(new Newtonsoft.Json.JsonSerializerSettings
{
TypeNameHandling = Newtonsoft.Json.TypeNameHandling.None
});
Most of our services work fine, however, one service is throwing this exception when it receives: UserProfileUpdatedEvent
Newtonsoft.Json.JsonSerializationException: Could not create an instance of type Common.Framework.Contracts.BaseEvent. Type is an interface or abstract class and cannot be instantiated.
In the SQS, I see the message in the error queue and the NServiceBus.EnclosedMessageTypes is:
"NServiceBus.EnclosedMessageTypes":
"ServiceA.Contract.Events.UserProfileUpdatedEvent,
ServiceA.Contract, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null;ServiceA.Contract.Events.BaseUserEvent,
...
public class UserProfileUpdatedEvent : BaseUserEvent { }
public class BaseUserEvent : BaseEvent
{
public Key UserKey { get; set; }
}
public abstract class BaseEvent : IEvent
{
public Key EventKey { get; set; }
public string Error { get; set; }
}
Please note, both the publisher and consumer services share the assembly that contains ServiceA.Contract.Events.UserProfileUpdatedEvent
We’re currently using the following versions:
NServiceBus 7.8.2
NServiceBus.AmazonSQS 5.6.3
NServiceBus.Newtonsoft.Json 2.4.0
NServiceBus.Persistence.Sql 6.6.2
NServiceBus.UniformSession 2.2.0
Should I instead use TypeNameHandling.Auto?