Does anyone know why I can serialize a Hashtable to a binary format but It wont serialize to a XML format?
Code:Imports System Imports System.Xml Imports System.Xml.Serialization Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim aCnt As Int16 Dim TestHash As New Hashtable() 'Load up some dummy classes into the ht For aCnt = 1 To 20 Dim TestCls As New clsTest("MyName" & aCnt.ToString, aCnt) TestHash.Add(aCnt, TestCls) Next 'Save it to disk as binary (works fine) If File.Exists("hash.dat") = True Then File.Delete("hash.dat") Dim fs As New FileStream("hash.dat", FileMode.CreateNew) Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter() bf.Serialize(fs, TestHash) fs.Close() 'Save it to disk in XML (doesn't work) If File.Exists("hash.xml") = True Then File.Delete("hash.xml") Dim fsx As New FileStream("hash.xml", FileMode.CreateNew) Dim bfx As New XmlSerializer(GetType(clsTest)) bfx.Serialize(fsx, TestHash) fsx.Close() End Sub End Class <Serializable()> Public Class clsTest Public sName As String Public MyID As Int16 Public Sub New() 'Default constructor End Sub Public Sub New(ByVal iName As String, ByVal iID As Int16) sName = iName MyID = iID End Sub End Class


Reply With Quote