How can I Serialize an object in one project and De-Serialize it in another?
Posted on 2014-11-25
In order to save certain program settings, I created an object, and added the <Serializable()> tag to it. Then in my code, I can save those settings using code like:
Dim saveFile As New FileStream(ExportFile_PathName, FileMode.Create, FileAccess.Write, FileShare.None)
Dim formatter As New BinaryFormatter
and load them using code like:
readFile = File.OpenRead(SettingsFile_PathName)
Dim BFormatter As BinaryFormatter
BFormatter = New BinaryFormatter
Settings = New clsCattle_Settings(CType(BFormatter.Deserialize(readFile), clsCattle_Settings))
This works perfectly when all of the code for saving and loading these serialized files is within the same program. However, what I would like to do is create a different program to create those settings files than the one that will be loading them. When I tried to do this, though, the program that is loading the file does not recognize the file format. So clearly there is some kind of meta-data in the serialized file stating where the object being serialized was created, and the BinaryFormatter in Program B cannot convert the class serialized in Program A to the same type of class.
So is there a way to get around this? Thank you.