Serialization Headaches

L

Luck

Hi, I really need some expert help... please! Basically, I need to
serialize a data structure object to a file using SOAP and then load and
de-serialize that file in ANOTHER program. When I serialize / deserialize
the object in the SAME application, it works fine but when I simply copy the
identical code to another application and try deserialization from that
second application, I get the error:

An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
system.runtime.serialization.formatters.soap.dll



Additional information: Parse Error, no assembly associated with Xml key
a1:http://schemas.microsoft.com/clr/nsassem/Empression_Client/Empression C
lient%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnu
ll General+SerializableData





A sample of the code I've been using to serialize and deserialize objects is
below:



Sub SaveSOAPData (ByVal path as String, ByVal o as Object)

Dim fs as FileStream = New FileStream (path, FileMode.Create)

Dim sf as New SoapFormatter (Nothing, New StreamingContext
(StreamingContextStates.File))



sf.Serialize (fs, O)

fs.close

End Sub





Function LoadSOAPData (ByVal path As String) As Object

Dim fs as FileStream = New FileStream (path, FileMode.Open)

Dim sf as New SoapFormatter (Nothing, New StreamingContext
(StreamingContextStates.File))



LoadSOAPData = sf.Deserialize (fs)

fs.close

End Function





I'd appreciate any help that anyone can offer.

Thanks in advance!!!!!
 
J

Jay B. Harlow [MVP - Outlook]

Luck,
When you serialize an object to a file, one of the items serialized is the
assembly doing the serialization, when you deserialize the object, the
system checks the current assembly version against the version in the
serialized object. If these versions are different you see the error.

I would recommend you use a single class library that does the actual
serialization & deserialization, ensuring the assembly version is constant.

One of the following articles on serialization discusses how you can change
the version info read from an assembly, which is used more for version 2
program being able to read version 1 versions of the serialized data, not so
program 1 can read program 2 data per se (read, as I would recommend a
single assembly used by both programs).

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top