为什么xml-可序列化类需要无参数构造函数?
public static string SerializeToXml(object obj){ XmlSerializer serializer = new XmlSerializer(obj.GetType()); using (StringWriter writer = new StringWriter()) { serializer.Serialize(writer, obj); return writer.ToString(); }}
未处理的异常:System.InvalidOperationException:CSharpConsole.foo无法序列化,因为它没有无参数的构造函数。在System.Xml.Serialization.TypeDesc.CheckSupported()(System.Xml.Serialization.TypeScope.GetTypeDesc(Type类型)、MemberInfoSource(System.Xml.Serialization.ModelScope.GetTypeModel(Type类型)、System.Xml.Serialization.ModelScope.GetTypeModel(Type类型(System.Xml.Serialization.ModelScope.GetTypeModel(Type类型)、System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type类型(布尔直接引用)、System.Xml.Serialization.XmlSerializer..ctor(Type类型下的XmlRootAttribute根、StringdefaultNamesspace(System.Xml.Serialization.XmlSerializer..ctor(Type类型)、StringdefaultName空间(System.Xml.Serialization.XmlSerializer..ctor(Type类型)
小唯快跑啊
皈依舞