0

在 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 无法序列化,因为它没有无参数构造函数。

我能解释一下如何设置无参数构造函数吗?

4

0 回答 0