Yes it does work. Make sure you marked your structure with the
<Serializable()> attribute. This tells the framework your object/structure
is ok to serialize:
<Serializable()> _
Structure foo
Dim val1 As Integer
Dim Val2 As String
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim bFormatter As New
Runtime.Serialization.Formatters.Binary.BinaryForm atter
Dim sFile As System.IO.FileStream = System.IO.File.Create("c:\test")
Dim x As foo
x.val1 = 123
x.Val2 = "some text"
bFormatter.Serialize(sFile, x)
sFile.Close()
End Sub
--
Justin Weinberg
Designing a PrintDocument or creating .NET graphics?
Save time with GDI+ Architect.
For more information, visit
http://www.mrgsoft.com
"Daryll SHatz" <ds****@cox.net> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
Does serialization work on custom data types via structures?
Dim bFormatter As New BinaryFormatter()
Dim sFile As FileStream = File.Create(FilePath)
Dim structure As myStruct
Dim val1 as Integer
Dim Val2 as String
End Structure
Dim aStruct as myStruct
aStruct.val1 = 123
aStruct.val2 = "some text"
bFormatter.Serialize(sFile, aStruct)
sFile.Close()
Everytime I use serialization on structures I get a PublicKeyToken=null is
not marked as serializable error. I can find much on serialization. Does
the object need some special interface to be serializ-able?