The type namespace.classname was not expected. Use the XmlInclude or SoapInclude attribute to specif

B

Bob Rock

Hello,

I have a web method that serializes a class that includes among its public
fields a System.Object field to which, at runtime, I assign instances of
various different classes.
When XmlSerializer tries serializing this public field's real content I get
a "The type namespace.classname was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.". I
suppose this is due to the fact that XmlSerializer has not been informed of
what the class types of class instances that may come to be loaded in this
public field at runtime.
I think I only need to specify on the System.Object field the instance
object classes that it may come to "contain" at runtime ... unfortunately
this cannot be done with the XmlInclude attribute (which can only be applied
to methods). How can I solve this problem???

Thx.


Bob Rock
 
M

Mickey Williams

The XmlSerializer class can only serialize types that it is aware of.

I've done this two ways:
1) Expose the property as an XmlElement and handle the serialization from
your object into XML yourself -- xs:any is the moral equivalent of
System.Object; or
2) Create an extension that intercepts the message, and manage the
serialization in the extension.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top