开发者

Sending interfaces as message in NServiceBus with the Binary Serializer

开发者 https://www.devze.com 2023-01-11 12:33 出处:网络
I recently moved to using the binary serializer to send messages with NServiceBus.My messages are all defined as interfaces and are instantiated using

I recently moved to using the binary serializer to send messages with NServiceBus. My messages are all defined as interfaces and are instantiated using

bus.Send<MessageType>(msg => msg.Proper开发者_如何学运维ty = someValue)

This leads to an exception being thrown from NServiceBus stating that

Cannot create an instance of an interface

I can see from the stack trace that the SimpleMessageMapper is being used, and after looking in the source can see it's making a call to Activator.CreateInstance.

I can't find anything in the documentation stating that it's not possible to do what I'm trying to do, is there a way to fix this?

Thanks, Matt


I only just started playing with nServiceBus, so all I can offer you is theory :).

Are you defining the implementation classes for your message interfaces, or is nServiceBus generating classes on its own? If the former, make sure you still have a default constructor and that the class and all fields/events are marked as [Serializable] or [NonSerialized]. If the latter, it's possible that nServiceBus doesn't know how to generate members which may be needed for (de)serialization. You may have to write and map the implementation class yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号