[英]MSMQ Complex Object Serialization/Deserialization
I am attempting to send a message to MSMQ utilizing the XmlFormatter for an object that contains a property of type object. 我试图使用XmlFormatter为包含类型为object的属性的对象发送消息到MSMQ。 If the object property is left null, the serialization/deserialization works flawlessly.
如果object属性保留为null,则序列化/反序列化将完美地进行。 However, if I assign an object I receive an exception when invoking .send.
但是,如果分配对象,则调用.send时会收到异常。 There was an error generating the XML document is the only information that I receive.
生成XML文档时出错,这是我收到的唯一信息。 Both classes are marked serializable.
这两个类都标记为可序列化。 Is there something else that I need to do?
还有什么我需要做的吗?
Thanks. 谢谢。
Even though your complex class declares a property as type object, when something is assigned to it, serialization sees the property as an object of the type assigned. 即使您的复杂类将一个属性声明为类型对象,但在为其分配了某些内容时,序列化也会将该属性视为已分配类型的对象。
For example, if you assign your object property a value of new CustomClass(), serialization will expect an object(), but find a CustomClass(), so serialization will fail. 例如,如果为对象属性分配新的CustomClass()值,则序列化将使用object(),但会找到CustomClass(),因此序列化将失败。 (Type CustomClasss was not expected)
(不希望输入CustomClasss类型)
If you assign your object property a value of new object(), I suspect the serialization will then work. 如果为您的对象属性分配一个新的object()值,我怀疑序列化将起作用。
I suspect that your objects are not properly serialized into XML. 我怀疑您的对象未正确序列化为XML。
how does it work for example if you simply assign a string value to the object property? 例如,如果您只是将字符串值分配给object属性,它如何工作?
You can use a small console app or the debugger to test how your classes are serialized and deserialized to/from xml and check the behavior of the XmlFormatter. 您可以使用小型控制台应用程序或调试器来测试如何将类从XML序列化和反序列化,以及检查XmlFormatter的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.