473,769 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Implementing IPersistStream using .Net Serialization

I have a .Net class (a collection) that already supports serialization.
It implements ISerializable.. .

Now, I need it to also support the COM interface IPersistStream. Among
other things, I need to be able to pass instances of this class to
methods of queued components (in COM+).

I want to "piggy back" my implementation of IPersistStream to what is
already being used for serialization. So, in the Save() method of
IPersistStream, the object serializes itself using the BinaryFormatter
and writes it to the given stream.

The problem is in the Load() method, I cannot figure out how to make
the object take the given stream and deserialize itself "in place".

Am I missing something?

Jul 21 '05 #1
2 1978
You could introduce a second class, which implements IPersistStream. In the
Save and Load methods of this class, you could just use standard
de/serialization code to persist/create instances of your main class.

HTH,
Mark

<re****@gmail.c om> schrieb im Newsbeitrag
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I have a .Net class (a collection) that already supports serialization.
It implements ISerializable.. .

Now, I need it to also support the COM interface IPersistStream. Among
other things, I need to be able to pass instances of this class to
methods of queued components (in COM+).

I want to "piggy back" my implementation of IPersistStream to what is
already being used for serialization. So, in the Save() method of
IPersistStream, the object serializes itself using the BinaryFormatter
and writes it to the given stream.

The problem is in the Load() method, I cannot figure out how to make
the object take the given stream and deserialize itself "in place".

Am I missing something?

Jul 21 '05 #2
Thanks for your help...

Your suggestion is not ideal since it would have required me to change
the signature of the methods that accept my class as a parameter to the
wrapper class that you suggest whenever that method need an
"IPersistSt ream-able" object.

But your suggestion gave me the idea that my class should wrap the
implementation class that I used as a data member instead of inheriting
from it. This way, I can deserialize the data member and won't need to
deserialize to "this" which doesn't seem to be possible right now. This
will require more work and is not as clean but I think it will work.

This still begs the question on why the serialization framework in .net
does not allow deserialization to this or self. Maybe this can be done
by overloading the Deserialize method on IFormatter to accept a
reference to the object where the stream should be deserialized:

// existing method
object Deserialize(Str eam deserialization Stream);
// suggested new method
void Deserialize(Str eam deserialization Stream, ref object graph);

With the new method, one can deserialize in place:

formatter.Deser ialize(stream, this);

This may also mean adding a method to ISerializable that does the
reverse of GetObjectData() which should be aptly named SetObjectData() .
Unless the serialization framework can call the (usually protected)
contructor that accepts (SerializationI nfo info, StreamingContex t
context) on an already existing object.

Is it too late for this?
Mark Rockmann wrote:
You could introduce a second class, which implements IPersistStream. In the
Save and Load methods of this class, you could just use standard
de/serialization code to persist/create instances of your main class.

HTH,
Mark

<re****@gmail.c om> schrieb im Newsbeitrag
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I have a .Net class (a collection) that already supports serialization.
It implements ISerializable.. .

Now, I need it to also support the COM interface IPersistStream. Among
other things, I need to be able to pass instances of this class to
methods of queued components (in COM+).

I want to "piggy back" my implementation of IPersistStream to what is
already being used for serialization. So, in the Save() method of
IPersistStream, the object serializes itself using the BinaryFormatter
and writes it to the given stream.

The problem is in the Load() method, I cannot figure out how to make
the object take the given stream and deserialize itself "in place".

Am I missing something?


Jul 21 '05 #3

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

Similar topics

1
2548
by: J Askey | last post by:
Is this object available in Access? If so, what do I need to set a reference to? My bigger picture is needing a way to take a .bmp out of a SQL database and put into both an CommandBarButton image and an Access.Image. I have found lots of peices to get the .bmp into a byte array, then the byte array into a StdPicture and then a StdPicture into an iPicture but Im needing the IPersistStream object to do this. Any other suggestions welcome...
1
7802
by: Eric Workman | last post by:
Hi Everyone- I would like to implement the IFormatter class to create a custom formatter that essentially does exactly what the System.Xml.Serialization.XmlSerializer does, but also would allow for the functionality of ISerializable (GetObjectData, and De-Serialization Constructor) so that I have more control over the Xml spit out and can include anything I would like rather than only public variables and the likes. I don't want to use...
3
5308
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I have implemented Clone() using serialization. When I call the Clone() function, the following exception is thrown at
2
2640
by: reycri | last post by:
I have a .Net class (a collection) that already supports serialization. It implements ISerializable... Now, I need it to also support the COM interface IPersistStream. Among other things, I need to be able to pass instances of this class to methods of queued components (in COM+). I want to "piggy back" my implementation of IPersistStream to what is already being used for serialization. So, in the Save() method of IPersistStream, the...
2
1608
by: Chris Puncher | last post by:
Hi. I have a RCW class that was generated by the VS.NET2003 IDE when I added a COM dll reference to my project. This all works fine when I call methods on it. My initial problem is that in ASP.NET I would like to add this to the Session object whilst using SQLServer as the session storage. Unfortunately, as this required the RCW class to be serializable, this won't work, and throws an exception saying you can't Serialize the Session...
3
8089
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one statement to VB.NET and this is crucial: re-implementing ISerializable.GetObjectData() in the DataTable derived class so serializing the datatable derived class will call this method and not the DataTable version (which is private, so overriding is also...
3
3347
by: Robin Tucker | last post by:
Does anyone have a VB.NET IPersistStream COM interface description I can cadge please? If I remember rightly, you have to "flatten" inherited COM interfaces (I think IPersistStream derives from IPersist or something). Thanks, Robin
0
2787
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I know I wrote before a week ago when I knew even less than now but I am getting better please anyone give me a clue or an example. Am I completely off track? I have a datarow in a table with the fields to map to an xsd. Then i call a web service upload method that wants the xml strongly typed to the xsd in a string. so I have generated a class from a xsd newcust.cs in .net 1.1 c# to start with just to see what it means to use an...
0
10208
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
9987
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
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
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
5294
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
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
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
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.