VB.net Serialization Issue

318 views Asked by At

I'm trying to save the following class to the user.config and I'm not sure what I'm doing wrong. Is the dictionary object not allowing the class to be serialized?

<Serializable()>Public Class RunInformation
    Public ExecutablePath As String
    <NonSerialized()> Public Settings As Dictionary(Of String, String)
    <NonSerialized()> Public ProcessId As Integer
    <NonSerialized()> Public Handle As IntPtr
    <NonSerialized()> Public TabPageHandle As IntPtr

    Public Sub New()
        ExecutablePath = ""
        Settings =  New Dictionary(Of String, String)
    End Sub
End Class

Saving:

Private Sub Form1_Closing(sender As Object, e As EventArgs) Handles MyBase.Closing
    my.Settings.Setting = New RunInformation()
    My.Settings.Save()
End Sub

XML File:

<userSettings>
    <BotManager.My.MySettings>
        <setting name="Setting" serializeAs="Xml">
            <value />
        </setting>
    </BotManager.My.MySettings>
</userSettings>
1

There are 1 answers

0
FloatingKiwi On

The problem is that your serializing the info as XML but using the binary serialization control attributes.

Use the attribute System.Xml.Serialization.XmlIgnore instead