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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim bFormatter As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim sFile As System.IO.FileS tream = System.IO.File. Create("c:\test ")
Dim x As foo
x.val1 = 123
x.Val2 = "some text"
bFormatter.Seri alize(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******** ******@TK2MSFTN GP12.phx.gbl...
Does serialization work on custom data types via structures?
Dim bFormatter As New BinaryFormatter ()
Dim sFile As FileStream = File.Create(Fil ePath)
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.Seri alize(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?