0

I'm trying to serialize a class object into XML but the result ends up having it doubled. I pass the object into the function only once but duplicates by the time it passes through serialization. When debugging, I noticed that my StringWriter has its CoreNewLine field set to Length = 2. I keep thinking that's the issue but don't know how to work a way to changing it. Is there something else I'm missing in regards to my serialization?

My XML Serialization Function

Public Shared Function ToXml(ByVal obj As Object) As String
    Try
        Dim serializer As XmlSerializer = New XmlSerializer(obj.[GetType]())

        Dim stringWrit As StringWriter = New StringWriter()
        Using writer = XmlWriter.Create(stringWrit)
            serializer.Serialize(stringWrit, obj)
            Return stringWrit.ToString()
        End Using

    Catch ex As Exception

        DumpException(ex)
        Return ex.ToString()
    End Try

End Function

My Class Object

<Serializable>
Public Class SPFolderOver

Public _files As List(Of SPFile)

Public _folders As List(Of SPFolderOver)

Public _name As String

Public _fullPath As String

<NonSerialized>
<XmlIgnore>
Public _props As Dictionary(Of EmailProperty, String)

Public _sp As Sharepoint

Public Property SPFiles() As List(Of SPFile)
    Get
        Return _files
    End Get
    Set(ByVal value As List(Of SPFile))
        _files = value
    End Set
End Property

Public Property SPFolders() As List(Of SPFolderOver)
    Get
        Return _folders
    End Get
    Set(ByVal value As List(Of SPFolderOver))
        _folders = value
    End Set
End Property


Public Property FolderName() As String
    Get
        Return _name
    End Get
    Set(ByVal value As String)
        _name = value
    End Set
End Property

<XmlIgnore>
Public Property Properties() As Dictionary(Of EmailProperty, String)
    Get
        Return _props
    End Get
    Set(ByVal value As Dictionary(Of EmailProperty, String))
        _props = value
    End Set
End Property

Public Property Folder() As Object
    Get
        'Return _folderObj
        Return Nothing
    End Get
    Set(ByVal value As Object)
        '_folderObj = value
    End Set
End Property


Public Property FullPath() As String
    Get
        Return _fullPath
    End Get
    Set(ByVal value As String)
        _fullPath = value
    End Set
End Property


Public Property SP() As Sharepoint
    Get
        Return _sp
    End Get
    Set(ByVal value As Sharepoint)
        _sp = value
    End Set
End Property

1 Answers1

0

Found the issue. Just changed the object fields from Public to Private.