K
Klaus Jensen
Hi!
This has been bugging me for days now...
I need to xmlserialize an object which contains a
collection/hashtable/array/whatever of childobjects.
-ParentObject
---Hashtable/Array/Collection
-----ChildObject
-----ChildObject
-----ChildObject
....
I use this code:
Dim formatter As New
System.Xml.Serialization.XmlSerializer(_databaseSettings.GetType)
Dim settingsFile As New System.IO.FileStream("Settings.xml",
IO.FileMode.Create)
Try
formatter.Serialize(settingsFile, _databaseSettings)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
settingsFile.Close()
End Try
<Serializable()> _
Public Class DataBaseSettings
Public Test As String
Public Items As Hashtable
End Class
When I try to run the code, I get an error when dimming the new formatter.
The error is: Additional information: There was an error reflecting type
'MyWinApp.Form1.DataBaseSettings'.
If I comment out "Public Items As Hashtable" serialization works just
fine, so the hashtable is the problem.
What am I doing wrong? Later I need to store objects in the hashtable. These
are also serializable individually. Do I need to do more than just add them
to the hashtable?
Thanks in advance
Klaus
This has been bugging me for days now...
I need to xmlserialize an object which contains a
collection/hashtable/array/whatever of childobjects.
-ParentObject
---Hashtable/Array/Collection
-----ChildObject
-----ChildObject
-----ChildObject
....
I use this code:
Dim formatter As New
System.Xml.Serialization.XmlSerializer(_databaseSettings.GetType)
Dim settingsFile As New System.IO.FileStream("Settings.xml",
IO.FileMode.Create)
Try
formatter.Serialize(settingsFile, _databaseSettings)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
settingsFile.Close()
End Try
<Serializable()> _
Public Class DataBaseSettings
Public Test As String
Public Items As Hashtable
End Class
When I try to run the code, I get an error when dimming the new formatter.
The error is: Additional information: There was an error reflecting type
'MyWinApp.Form1.DataBaseSettings'.
If I comment out "Public Items As Hashtable" serialization works just
fine, so the hashtable is the problem.
What am I doing wrong? Later I need to store objects in the hashtable. These
are also serializable individually. Do I need to do more than just add them
to the hashtable?
Thanks in advance
Klaus