Serialization Problem

VonEhle

Active member
Joined
Feb 20, 2006
Messages
26
Programming Experience
Beginner
This is my first time trying to serialize something. I'm getting an error that says:

Type 'System.Windows.Forms.Form' in Assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

The class is marked serializable, so I'm unsure what this is telling me.

VB.NET:
Sub SaveGame()
Dim serTexas As New ArrayList
Dim GameInfo As New frmMain
GameInfo.intPlayers = intPlayers
GameInfo.DealCards = DealCards
GameInfo.lstP1 = lstP1
GameInfo.chkP1 = chkP1
GameInfo.lstP2 = lstP2
GameInfo.chkP2 = chkP2
GameInfo.lblTurn = lblTurn
GameInfo.lstRiver = lstRiver
GameInfo.lblRiver = lblRiver
GameInfo.intCardNo = intCardNo
GameInfo.intRound = intRound
serTexas.Add(GameInfo)
Dim s As New FileStream("c:\SavedGame.dat", FileMode.Create)
Dim f As New BinaryFormatter
[COLOR=red]f.Serialize(s, serTexas)  'Error points to this line[/COLOR]
s.Close()
End Sub
 
System.Windows.Forms.Form class is not marked as serializable and you can't fix this by marking your own inherited form. You have to store your info in a class of your own.
 
I'm sure this is elementary stuff, but I can't figure out how to get info to pass from a form to a class library. How is this done?
 
You don't need a Class Library, just a simple class:
VB.NET:
<Serializable()> Public Class myclass
Public member1, member2 As String
End Class
You can insert new class item to your project and just add class members.

When you need one of those you create a new one like you always have done:
VB.NET:
Dim someof As New myclass
 
Great! Finally getting somewhere.

Last question, I've got everything working but my listboxes. The boxes themselves are reappearing after deserializing, but not their contents. How do I get the contents?
 
What do you mean? Have you serialized the content, and added the same content back to listbox from the deserialized data?
 
Back
Top