XML Deserialization problem.

Hello,

As you might have guessed from the subject line, I am having some problems (In Visual Basic 2005 and .NET 2003) with XmlSerializer.Deserialize functionality. The code giving me the problem is as follows:

Public Function ReadOptions(ByVal fileName As String) As Boolean

If System.IO.File.Exists(fileName) = True Then

Dim xs As New System.Xml.Serialization.XmlSerializer(ConfigData.GetType)

Dim fs As New System.IO.FileStream(fileName, IO.FileMode.Open)

Dim reader As New System.Xml.XmlTextReader(fs)

ConfigData = xs.Deserialize(reader)

fs.Close()

Return True

End If

Return False

End Function

The problem is that every time I run this function, the file I am reading from gets deleted and refreshed with the results of the ConfigStruct.New() member method. Everything previously in the file is trashed. I have looked over all of the documentation I could find about this, and nothing I have tried seems to have worked at all. This is a really stupid simple thing. I'm just trying to read config data from a file. The serialization and writing of the class seems to work just fine. It is just the reading back the data that isn't working properly.

Any suggestions

Thanks,

Mark Warner.



Answer this question

XML Deserialization problem.

  • VirusFree

    Well, I fixed it. As it turns out, I'm retarded.

    Just in case anyone is curious, or having a similar problem, I had a stray call to the related SaveOptions() function elsewhere in the program that was always running at startup, and apparently before the program had a chance to run the above function. It was not in the Form1.Load event, rather it was something stupid I did where I, for reasons that now escape me, wanted to save the config file every time the window was resized or moved. Obviously, that particular event happens automatically at startup. Like I said, I am retarded (and fairly new to VB).


  • XML Deserialization problem.