我有Payload
类型object
的属性
我用匿名类型填写Payload,然后发送它,然后我得到这个丑陋的错误:
2014-03-12 15:50:25,649 [7]
ERROR NServiceBus.Unicast.Transport.TransportReceiver [(null)] <(null)> -
Failed to serialize message with ID: fc8d44c1-3750-4658-ba91-a2ec010507aa`
System.Runtime.Serialization.SerializationException:
An error occurred while attempting to extract logical messages from
transport message NServiceBus.TransportMessage --->
Newtonsoft.Json.JsonSerializationException:
Error resolving type specified in
JSON '<>f__AnonymousType2`2[[System.String, mscorlib],[System.Int32,mscorlib]], MyProject'.
Path '[0].Payload.$type', line 1, position 366. ---> Newtonsoft.Json.JsonSerializationException: Could not load assembly 'MyProject'.
答案 0 :(得分:2)
我遇到了这个问题 - 问题出在json.net上,而不是NServiceBus Json.Net要求能够将类型反序列化为严格的对象,它只是不能。
有几种方法可以做到这一点,您可以将有效负载对象更改为一个接口,这将强制NServiceBus使用TypeNameHandling.None,这反过来将导致Json.Net反序列化,即使不知道类型。
或者您可以编写自己的序列化程序,可能基于Json.Net,但始终打开TypeNameHandling.None。
我没有找到保持TypeNameHandling的理由,我想也许特定的团队决定这样做。