471,356 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

Need some help with serialization please

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.SerializationExcepti on' 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.
Jul 22 '05 #1
5 1035
> 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.

Jul 22 '05 #2
> 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.

Jul 22 '05 #3
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
Jul 22 '05 #4
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.

Jul 22 '05 #5
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.

"Tom Rahav" <to******@nospam.nospam> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl...
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.SerializationExcepti on' 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.

Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by TrvlOrm | last post: by
7 posts views Thread by Timothy Shih | last post: by
4 posts views Thread by =?Utf-8?B?cm9kY2hhcg==?= | last post: by
1 post views Thread by lchristy0213 | last post: by
21 posts views Thread by SpecialKay | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.