Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

C# Object serialization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
linuxfedora@yahoo.com.hk - 24 Sep 2007 05:44 GMT
I know how to serialize a object into a file. But if i want to
serialize several different objects into the same file and not at the
same time, Then how can i do it?Thanks
For example:

i need to serialize ClassA object first, then after 1 minute, i need
to serialize ClassB objec to the same file.

And finally, i need to deserialize them and has the ClassA object and
ClassB object from the file.
Lloyd Dupont - 24 Sep 2007 05:56 GMT
BinaryFormatter.Selrialize(Stream s.....)

just use the same (unclosed) stream hey!

Signature

Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com

>I know how to serialize a object into a file. But if i want to
> serialize several different objects into the same file and not at the
[quoted text clipped - 6 lines]
> And finally, i need to deserialize them and has the ClassA object and
> ClassB object from the file.
Frans Bouma [C# MVP] - 24 Sep 2007 09:29 GMT
> I know how to serialize a object into a file. But if i want to
> serialize several different objects into the same file and not at the
[quoted text clipped - 6 lines]
> And finally, i need to deserialize them and has the ClassA object and
> ClassB object from the file.

    If you serialize them separately to a memorystream and save the
byte[] to a file, you have a problem that you can't find the
blockstarts back.

    So you have to create some sort of index in the file and append a
byte[] which is the result of the serialization of an object. Then when
you deserialize one object, you can find it back inside the file, load
the byte[] and deserialize it. Otherwise you'll run into problems.

    FB

Signature

------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Jeremy - 24 Sep 2007 19:35 GMT
Can you create an object that wraps objects A and B.  So for example you
have an object with properties of type ClassA and ClassB.  Then you
serialize your wrapper object.  The first time you serielize it, the ClassB
property will be null so the file will only contain object A (plus the
wrapper).  The second time you serialize, you assigned the ClassB property
so now both objects will be serialized (plus the wrapper).  The downside is
that your wrapper adds a bit of overhead in the file size, but it should be
very little.

>I know how to serialize a object into a file. But if i want to
> serialize several different objects into the same file and not at the
[quoted text clipped - 6 lines]
> And finally, i need to deserialize them and has the ClassA object and
> ClassB object from the file.
linuxfedora@yahoo.com.hk - 25 Sep 2007 05:06 GMT
i can now deserialize serial different object. But i find that if i
deserialize the object by the same application, then it is okey, but
if i write another program in another Project to deserialize the
stored data file that stored the serialized object, then when i try to
deserialize it, it will have the exception: "Unable to find assembly
'Test1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", so how
can i ensure that different application can deserialize the stored
data file??Thanks
Jeremy - 25 Sep 2007 17:33 GMT
Create a seperate class library project and put your classses in it.  Then
when you need to use those class types from any of your applications
reference that assembly.

>i can now deserialize serial different object. But i find that if i
> deserialize the object by the same application, then it is okey, but
[quoted text clipped - 4 lines]
> can i ensure that different application can deserialize the stored
> data file??Thanks

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.