简体   繁体   中英

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. If the object property is left null, the serialization/deserialization works flawlessly. However, if I assign an object I receive an exception when invoking .send. There was an error generating the XML document is the only information that I receive. 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. (Type CustomClasss was not expected)

If you assign your object property a value of new object(), I suspect the serialization will then work.

I suspect that your objects are not properly serialized into XML.

how does it work for example if you simply assign a string value to the object property?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM