Converting your object to bytes or using the memorystream and binaryformatter seem the same to me.
Consider this. If I was to take down my house brick by brick and then give you the bricks you would need plans on how to put it back together.
The same is true of objects being passed from program to program. When you pass an object from one process to another you will always need to include a reference to the objects library.
Instead of using low level sockets, have you thought about using Channels.
Look at the System.Runtime.Remoting.Channels namespace. There are objects there that suport RPC.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
I re-read your original post and realised you do not need to pass a reference (which is what channels do by the way) so I had another think.
Because C# does not allow direct access to the raw implementation (that would be unmanaged), the quick and dirty way to do it like C++ is to add a method to extract the data to a byte array and then at the remote end have a contructor that takes the raw byte data to form the object.
However, it is possible to do this using the BinaryFormater.
If you stream the binaryformater output to a file you will see that it contains fully qualified type names for the objects (this is to maintain strong typing).
The BinaryFormater.Binder property provides a mechanism to override this typing.
Set the Binder property to a class derived from SerializationBinder. This allows you to override the requested type with one from a different library.
SerializationBinder Class Help from MSDN
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187