[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Implementing a serialization formatter

Posted on 2003-11-06
4
Medium Priority
?
502 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
3 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month19 days, 14 hours left to enroll

873 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