使用二进制序列化器在 NServiceBus 中将接口作为消息发送

发布于 2024-09-13 17:11:26 字数 373 浏览 2 评论 0原文

我最近开始使用二进制序列化器通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-09-20 17:11:26

您是为消息接口定义实现类,还是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文