XML序列化反映类型

时间:2013-08-05 11:55:07

标签: xml vb.net serialization reflection xml-serialization

在Visual Basic.NET中,我无法将对象序列化为XML。

以下是我要序列化的课程:

<Serializable> 
Public Class ClassTest
    Public string1 As String
    Public string2 As String
    Public ListOfString As List(Of String)
    Public dreamscript As New DreamScript
End Class

这是我用来序列化对象的函数:

    Public Sub SerializeObjectToXML(FileName As String, ObjectToSerialize As Object, ObjectType As Type)
        Dim Serializer As New XmlSerializer(ObjectType)
        Dim Writer As New StreamWriter(FileName)
        Serializer.Serialize(Writer, ObjectToSerialize)
        writer.Close()
    End Sub

这是错误:

  

有一个错误反映了'CanLucidDream.ClassTest'类型。

在这一行:

Dim Serializer As New XmlSerializer(ObjectType)

更新

原因如下:Message = System.IO.FileInfo无法序列化,因为它没有无参数构造函数。

我是否可以解释如何设置无参数构造函数。

0 个答案:

没有答案