473,796 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

serializing non-serializable data members

How do I write my own serialization of a class that has
non-serializable data members?
this problem arose when I tried to serialize RSAParameters, for which
the private stuff is not serializable

Sep 26 '06 #1
4 3029
On 25 Sep 2006 22:47:42 -0700, "dani k" <da*********@gm ail.comwrote:
>How do I write my own serialization of a class that has
non-serializable data members?
this problem arose when I tried to serialize RSAParameters, for which
the private stuff is not serializable
I'm afraid you can't serialize the private fields of objects you don't have the
source for, but if the private fields are exposed as properties, you might be
able to inherit from the class and serialize those properties in the derived
class.

Did I misunderstand your question?
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Sep 26 '06 #2

dani k wrote:
How do I write my own serialization of a class that has
non-serializable data members?
this problem arose when I tried to serialize RSAParameters, for which
the private stuff is not serializable
If your sole purpose is serializing all the members, you can create a
method which will save all the members of your class, may be it private
or public, to a binary or simple text file. May be you can put some
file name as parameter to this method.
Another method of your class will read some binary / text file and just
assign the value to all the members serialized from the first method.
This could be a solution for your problem.
These both methods will be public so that any instance of your class
gives access to these methods.
I think this should work for you.
It will be a tedious job once, but you can define your own format for
the file also in what format you save your data.
Hope i understood your question and am clear in my description.

Thanks !

Sep 26 '06 #3
Hi,

Implement ISerializable on your class. The formatter that you use for serialization will use your serialization code instead of
default serialization, which tries to serialize all members.

In your implementation of ISerializable.G etObjectData add the information that needs to be persisted. Since you can't add the
RSAParameters object to the SerializationIn fo, only add the information that is required to reconstruct the RSAParameters object
during deserialization .

A constructor on your class that takes SerializationIn fo and StreamingContex t as arguments is required for deserialization . In this
constructor, read the persisted data from the SerializationIn fo object and populate your object's fields. Read the RSAParameters
data that you persisted and construct a new instance.

HTH

--
Dave Sexton

"dani k" <da*********@gm ail.comwrote in message news:11******** **************@ i3g2000cwc.goog legroups.com...
How do I write my own serialization of a class that has
non-serializable data members?
this problem arose when I tried to serialize RSAParameters, for which
the private stuff is not serializable

Sep 26 '06 #4

Otis Mukinfus wrote:
On 25 Sep 2006 22:47:42 -0700, "dani k" <da*********@gm ail.comwrote:
How do I write my own serialization of a class that has
non-serializable data members?
this problem arose when I tried to serialize RSAParameters, for which
the private stuff is not serializable

I'm afraid you can't serialize the private fields of objects you don't have the
source for, but if the private fields are exposed as properties, you might be
able to inherit from the class and serialize those properties in the derived
class.

Did I misunderstand your question?
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Yes, I am afraid I didn't state the problem very well. Thanks anyway.
Anyway, I figured it out: I included an RSAParameters object as a
member in a new class that implements the ISerializable interface, and
wrote my own serialization code.
It works!
Here is the code:

public class AllSerRSAParame ters:ISerializa ble
{
private RSAParameters RSAKeyInfo;

public AllSerRSAParame ters(RSAParamet ers rhs)
{
RSAKeyInfo = rhs;
}
public AllSerRSAParame ters(Serializat ionInfo si,
StreamingContex t context)
{
RSAKeyInfo.D = (Byte[]) si.GetValue( "D", typeof(Byte[]));
RSAKeyInfo.DP = (Byte[]) si.GetValue( "DP",
typeof(Byte[]));
RSAKeyInfo.DQ = (Byte[])si.GetValue("D Q", typeof(Byte[]));
RSAKeyInfo.Expo nent = (Byte[])si.GetValue("E xponent",
typeof(Byte[]));
RSAKeyInfo.Inve rseQ = (Byte[])si.GetValue("I nverseQ",
typeof(Byte[]));
RSAKeyInfo.Modu lus = (Byte[])si.GetValue("M odulus",
typeof(Byte[]));
RSAKeyInfo.P = (Byte[])si.GetValue("P ", typeof(Byte[]));
RSAKeyInfo.Q = (Byte[])si.GetValue("Q ", typeof(Byte[]));
}

public RSAParameters GetRSAParameter s()
{
return RSAKeyInfo;
}

#region ISerializable Members

[SecurityPermiss ion(SecurityAct ion.Demand,
SerializationFo rmatter = true)]
public void GetObjectData(S erializationInf o si,
StreamingContex t context)
{
si.AddValue("D" , RSAKeyInfo.D, typeof(Byte[]));
si.AddValue("DP ", RSAKeyInfo.DP, typeof(Byte[]));
si.AddValue("DQ ", RSAKeyInfo.DQ, typeof(Byte[]));
si.AddValue("Ex ponent", RSAKeyInfo.Expo nent,
typeof(Byte[]));
si.AddValue("In verseQ", RSAKeyInfo.Inve rseQ,
typeof(Byte[]));
si.AddValue("Mo dulus", RSAKeyInfo.Modu lus, typeof(Byte[]));
si.AddValue("P" , RSAKeyInfo.P, typeof(Byte[]));
si.AddValue("Q" , RSAKeyInfo.Q, typeof(Byte[]));
}

#endregion
}

Sep 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1453
by: Uri | last post by:
Hi, I am using apaches' XMLSerializer to serialize a DOM Document as an OutputStream. 2 questions: 1) Is there a standard way of serializing XML(without using a specific parser)? 2) Should there be any difference between explicitly setting the OutputFormat with "UTF-8" encoding or not setting it at all? from what I read the default is "UTF-8" anyway, and the only difference would be the "encoding" directive in the xml declaration....
0
1332
by: Ante Smolcic | last post by:
Hi all, I have an ArrayList that contains items of type A. I declared the XmlArrayItem atribute for that type. Now I have an derived type B (from A) also contained in the ArrayList but I get an error when serializing. Can this be made without redeclaring the ArrayList special attributes? The problem is that the class B is in different namespace!
1
2088
by: Ivo Bronsveld | last post by:
All, I have quite a challenging task ahead of me. I need to write an object model (for code access) based on a schema, which cannot be made into a dataset because of it's complexity. So I created a couple of objects and serializing it into XML based upon the schema works perfectly. The XML / Schema looks something like this:
6
3389
by: Rein Petersen | last post by:
Hi Folks! Here's a strange behaviour: Without a properties SET accessor (see code below), the property will not serialize. public class myObject {
2
3524
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: + More ways to contact me __________________________________________________________________
2
3099
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string format. I can, of course, serialize a class to a file, either binary or XML, but this is not what I am looking for. Currently I am using ToString() or Convert.xxx to do this, but thought that if there was a true serializer, deserializer, that would be...
6
13359
by: Marco Herrn | last post by:
Hi, I need to serialize an object into a string representation to store it into a database. So the SOAPFormatter seems to be the right formatter for this purpose. Now I have the problem that this formatter writes into a stream. And I am not used enough to C# to convert this to a string. I tried the following code: MemoryStream stream= new MemoryStream() ; IFormatter formatter = new SoapFormatter();
4
1680
by: Jason Shohet | last post by:
We are thinking of serializing an object & passing it toseveral functions on web service. This will happen about 35 times as the page loads. The class has about 20 attributes. We're not sure on the impact serializing something has on an asp.net page rendering, compared to say, hitting the db or something like that. THanks Jason Shohet
4
1310
by: mookid8000 | last post by:
Good day group! I have created a nice filtering plugin system, where all filters derive from a Filter class, and they pass a PictureData object between them. I have a problem though. I am able to save the filter setup by serializing the filter chain to a file, and there seems to be no problems when de-serializing, as the filter chain will seem to re-generate properly.
3
2810
by: Thyme | last post by:
Each time I serialize an object using XmlSerializer I get a structure like this: <?xml version="1.0"?> <MyType> .. .. </MyType> <?xml version="1.0"?> <MyType> ..
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.