Need some help with serialization please

  • Thread starter Thread starter Tom Rahav
  • Start date Start date
T

Tom Rahav

Hello All!

I want to store some information about application's evrironment, such as
allowed modules, application's paths, etc. For this purrpose, I created a
class called SystemEnvironment that contains all the variables I need to
store, and methods for serialization and deserialization the object.
What I want to do is to create an object with all the values I want and
serialize it into a binary file, and to this in one application called
SupportTool.
Then, I want to copy the binary file into a different application's folder
and deserialize the object into the new application, so it can get the
pre-configured preferences I set in the SupportTool.
When I tried to do so, everything went well till I tried to deserializie the
object into the new application (that contains the exact class as the
SupportTool). I got the following error message:

"An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll
Additional information: Cannot find the assembly SupportTool,
Version=1.0.2011.37510, Culture=neutral, PublicKeyToken=null."

Can anyone explain me how can I perform such task?

Thanks!
Tom Rahav.
 
object into the new application (that contains the exact class as the
SupportTool). I got the following error message:

What does this mean? I suspect that you added the same code to both
projects. Even though the code is the same, the types are completely
different and they cannot (de)serialize one another.

Your best bet would be to place the class you wish to (de)serialize
into its own Class Library and then reference the resultant .dll from
both project. That will ensure that the types are the same.
 
object into the new application (that contains the exact class as the
SupportTool).

Does this mean that you have referenced a .dll that contains the exact
class or merely added the class .vb file into the second project? If
you just added the .vb file to the second project, you are not using
the same class. It is a completely different type, even though the
code is the same.

Your best bet is to place the class you want to (de)serialize into its
own Class Library and then reference it from both projects. That will
insure that you are (de)serializing the *same* type.
 
Tom,

You can try this sample from Tom Shelton

(Assuming that you have set the serializable tag)

\\\
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function


Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function
///

I hope this helps a little bit?

Cor
 
Sorry for the duplicate post. Google Groups displayed an error the
first time I submitted my post so I didn't think it got through.
 
Hi!
Thank you very much for your help!!
I created a new .dll file contains the class I need, added it into both
projects and it works PERFECT!
Thanks alot again for your help!
Tom.
 
Back
Top