Solved

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

Posted on 2014-11-25
2
95 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 74

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

10 Experts available now in Live!

Get 1:1 Help Now