Solved

Implementing a serialization formatter

Posted on 2003-11-06
4
484 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

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

14 Experts available now in Live!

Get 1:1 Help Now