Solved

How can I Serialize an object in one project and De-Serialize it in another?

Posted on 2014-11-25
2
98 Views
Last Modified: 2014-12-02
Hello,

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
        formatter.Serialize(saveFile, Settings)

        saveFile.Close()


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))


                readFile.Close()


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.

Vijay
0
Comment
Question by:vdurbal
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40465422
You need to create a common library that both projects share. Place the settings class in that library. Then you should be able to (de)serialize across those boundaries.
0
 

Author Closing Comment

by:vdurbal
ID: 40476565
I'll try that.  Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now