使用二进制序列化器在 NServiceBus 中将接口作为消息发送
我最近开始使用二进制序列化器通过 NServiceBus 发送消息。我的消息全部定义为接口并使用实例化
bus.Send<MessageType>(msg => msg.Property = someValue)
这会导致 NServiceBus 抛出异常,指出
无法创建实例 界面
中看到正在使用 SimpleMessageMapper,并且在查看源代码后可以看到它正在调用 Activator.CreateInstance。
我在文档中找不到任何内容表明不可能执行我想要执行的操作,有办法解决此问题吗?
谢谢, 马特
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是为消息接口定义实现类,还是 nServiceBus 自己生成类?如果是前者,请确保您仍然有默认构造函数,并且类和所有字段/事件都标记为 [Serialized] 或 [NonSerialized]。如果是后者,nServiceBus 可能不知道如何生成序列化(反)序列化所需的成员。您可能必须自己编写和映射实现类。
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.