我有三个类:
Class Image : Asset
Class Sound : Asset
Class Video : Asset一切都可以序列化,但是当我创建这个项目时:
Class Master
List<Asset> assets //property此类的实例,例如:
Image i = new Image();
Sound s = new Sound();
Video v = new Video();
Master m = new Master( new List<Asset>{i,s,v} )它不会序列化,并出现异常“InvalidOperationException-生成XML文档时出错”,并且在innerException中:{“不需要类型MyApplication.Video。请使用XmlInclude或SoapInclude属性指定静态未知的类型。”}
。。有什么想法吗?
发布于 2013-03-01 22:26:59
在Asset类上添加XmlInclude属性:
[XmlInclude(typeof(Video))]
[XmlInclude(typeof(Sound))]
[XmlInclude(typeof(Image))]
public class Asset
{
...
}https://stackoverflow.com/questions/15159931
复制相似问题