Solved

Implementing a serialization formatter

Posted on 2003-11-06
4
483 Views
Last Modified: 2008-02-01
Hi,

I am trying to implement my own formatter that implements and adheres to the standards of the IFormatter interface. I have run into a bit of an issue trying to serialize classes that implement the ISerializable interface. Specifically, I don't know how to repopulate the members (via the special New constructor). The MSDN documentation for the FormatterServices.PopulateObjectMembers function claims that:

"if the object implements ISerializable, the populating is handed off to the object itself. If a matching surrogate is not found, and the object does not implement the ISerializable interface, then deserialization populates each field listed in members, with the corresponding value listed in data."

Based on this, I figure I need to call this method to populate the data for classes that implement ISerializable. What I can't figure out is what to pass for the "members()" parameter. It expects an array of MemberInfo objects, but I can't construct those, the constructor is protected. I even tried to create my own class that inherits from MemberInfo, but it just threw an error when I passed it in saying:

"An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Only FieldInfo, PropertyInfo, and SerializationMemberInfo are recognized."

Does anyone have any ideas as to how I can get around this? Does anyone know what a SerializationMemberInfo is?

Thanks,
Zaphod.
0
Comment
Question by:Z_Beeblebrox
  • 2
4 Comments
 
LVL 4

Expert Comment

by:NetPointer
ID: 9703098
This might help u...
http://www.c-sharpcenter.com/InsideDotNet/IDN_CustomSerial.asp


Regards,
NetPointer
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 9703168
Hi,

Thanks for the link, but unfortunately it discusses how to make a class that implements ISerializable, not how to make a class that calls a class that implements ISerializable.

Zaphod.
0
 
LVL 7

Accepted Solution

by:
Z_Beeblebrox earned 0 total points
ID: 9804703
I figured out one way to do this. What you can do is add the structure to an instance of the System.Runtime.Serialization.ObjectManager with its associated SerializationInfo. Then when you call DoFixups on the ObjectManager, it will call the constructor.

Zaphod.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
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…

746 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

11 Experts available now in Live!

Get 1:1 Help Now