Problem Deserialzing

bigfoot3d

Well-known member
Joined
Mar 11, 2007
Messages
56
Location
New Orleans, LA
Programming Experience
3-5
The problem I am having with Serialization is the Deserialization side I believe.

I get this SerializationException "Unable to find assembly 'HFHRemoteHelpClientApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."

This is where the error occurs:

VB.NET:
[SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] getdata2()[/SIZE]
[SIZE=2][COLOR=#008000]'deserialize[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bf [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Runtime.Serialization.Formatters.Binary.BinaryFormatter[/SIZE]
[SIZE=2]mem2.Seek(0, IO.SeekOrigin.Begin)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] p [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ClassPacket = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](bf.Deserialize(mem2), ClassPacket) [COLOR=red]<=== Error :([/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'save file/set text[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].SetLabel1Text(Encoding.ASCII.GetString(p.data))[/SIZE]
[SIZE=2][COLOR=#008000]'savefile(p)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'update UI (listbox)[/COLOR][/SIZE]
[SIZE=2]UIlistbox(p.filename)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

At the bottom of both the client and the server I have this serializable class.
VB.NET:
[SIZE=2]<Serializable()> [/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] ClassPacket[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] filename [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] data() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]

Any ideas?:confused:
 
If you define ClassPacket class in two different assemblies then these two classes are two different classes and can't be serialized between. You have to define this class in a Class Library project and compile it to the dll assembly and reference this by both parties that want to serialize this.
 
Ok, guess I have to do that then. I didn't want to have a DLL with my EXE file when I was done, but guess I don't have a choice. Either that or don't serialize.:p

Thanks again for the response.
 
Either that or use the System.Xml.Serialization.XmlSerializer instead of the BinaryFormatter.
 
Thank You

John, I took your advice and went ahead with the XML Serialization.

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bf [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Xml.Serialization.XmlSerializer([/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](ClassPacket))[/SIZE]

:) ;) Thanks bunches:D :cool:
 
Back
Top