1

I have these 3 classes:

Class Image : Asset
Class Sound : Asset
Class Video : Asset

everything serializes ok but when i create this item:

Class Master
List<Asset> assets //property

an instance of this class for example:

Image i = new Image();
Sound s = new Sound();
Video v = new Video();
Master m =  new Master( new List<Asset>{i,s,v} )

it does not serialize with exception "InvalidOperationException-There was an error generating the XML document" and in the innerException : {"The type MyApplication.Video was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}

.. any idea??

4

1 回答 1

6

Add the XmlInclude attribute on the Asset class:

[XmlInclude(typeof(Video))]
[XmlInclude(typeof(Sound))]
[XmlInclude(typeof(Image))]
public class Asset
{
    ...
}
于 2013-03-01T14:26:58.627 回答