473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 1947
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.com> schrieb im Newsbeitrag
news:11**********************@o13g2000cwo.googlegr oups.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
"IPersistStream-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(Stream deserializationStream);
// suggested new method
void Deserialize(Stream deserializationStream, ref object graph);

With the new method, one can deserialize in place:

formatter.Deserialize(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 (SerializationInfo info, StreamingContext
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.com> schrieb im Newsbeitrag
news:11**********************@o13g2000cwo.googlegr oups.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
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...
1
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...
3
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...
2
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...
2
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...
3
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...
3
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.