views:

105

answers:

1

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.Property = 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

A: 

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.

Mike Strobel
Hi Mike,That sounds possible, I'd assumed NServiceBus was creating proxies internally as I haven't got any implementation classes for the messages. I just find it a bit strange that it was working fine with the XmlSerializer, but not with Binary.Thanks,Matt
mattcole