Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class serialization problem.

Status
Not open for further replies.

jcisco

Programmer
Sep 17, 2002
125
0
0
US
Ok. i'm having issues with serialization and i'm hopin someone can point me in the correct direction.

I have a class called Profile
<Serializable()> Public Class Profile
..... code........ methods.. blah blah..
End Class

and i have a save profile button on a form that uses this code

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
If lblb1.Text <> "" And lblb2.Text <> "" And lblb3.Text <> "" And lblb4.Text <> "" And lblb5.Text <> "" And lblb6.Text <> "" And lblb7.Text <> "" And lblb8.Text <> "" And lblb9.Text <> "" And lblb10.Text <> "" Then
'create class profile
Dim mProfile As New Profile
mProfile.addMappedItem = lblb1.Text & "|" & b1.BackColor.ToArgb
mProfile.addMappedItem = lblb2.Text & "|" & b2.BackColor.ToArgb
mProfile.addMappedItem = lblb3.Text & "|" & b3.BackColor.ToArgb
mProfile.addMappedItem = lblb4.Text & "|" & b4.BackColor.ToArgb
mProfile.addMappedItem = lblb5.Text & "|" & b5.BackColor.ToArgb
mProfile.addMappedItem = lblb6.Text & "|" & b6.BackColor.ToArgb
mProfile.addMappedItem = lblb7.Text & "|" & b7.BackColor.ToArgb
mProfile.addMappedItem = lblb8.Text & "|" & b8.BackColor.ToArgb
mProfile.addMappedItem = lblb9.Text & "|" & b9.BackColor.ToArgb
mProfile.addMappedItem = lblb10.Text & "|" & b10.BackColor.ToArgb

saveBin(mProfile) 'call the formatter method for save
End If
End Sub

Private Sub saveBin(ByVal mProfile As Profile)

Dim saveFile As IO.FileStream
SaveFileDialog1.DefaultExt = "bin"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
saveFile = IO.File.OpenWrite(SaveFileDialog1.FileName)
saveFile.Seek(0, IO.SeekOrigin.End)
Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
formatter.Serialize(saveFile, mProfile)
saveFile.Close()
MsgBox("saved")
End If

End Sub


Now when i run this project i get a runtime error.

--------------
:)
 
here is the err message.
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll

Additional information: The type Microsoft.VisualBasic.Collection in Assembly Microsoft.VisualBasic, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a is not marked as serializable.

I have also tried this code.
Dim saveFile As IO.FileStream
SaveFileDialog1.DefaultExt = "bin"

If SaveFileDialog1.ShowDialog = DialogResult.OK Then
'saveFile = IO.File.OpenWrite(SaveFileDialog1.FileName)
'saveFile.Seek(0, IO.SeekOrigin.End)

Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim stream As IO.Stream = New IO.FileStream(SaveFileDialog1.FileName, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)


formatter.Serialize(stream, mProfile)

--------------
:)
 
found my problem and fixed it. i was trying to do Serialization with a collection. which doesn't work. changed it to an arraylist and things are working just fine now. thanks.


--------------
:)
 
My attention was caught by the statement "trying to do Serialization with a collection. which doesn't work." I have found documentation on how to serialize a collection that inherits from ICollections. However, I have not been able to get it to work. Could you point me to where you found information about serialization of a collection not working? Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top