Serialization of code to remote machine

  • Thread starter Thread starter Andrew Reeves
  • Start date Start date
A

Andrew Reeves

I am trying to serialize and deserialize an object from
one machine to another. This I have no problem with
provided both machines have references to the class. When
I try to deserialize a class MyObject on a remote machine
that knows nothing about MyObject it throws an exception
stating it is unable to find the assembly.

I notice that the Terrarium sample application seems to
do this though. How is this done? Do you have to inherit
a base class that both parties know about? I have tried
this with no success.

Thanks

Andrew Reeves
(e-mail address removed)#NoSpam#
(Remove #NoSpam# from email address)
 
I am trying to serialize and deserialize an object from
one machine to another. This I have no problem with
provided both machines have references to the class. When
I try to deserialize a class MyObject on a remote machine
that knows nothing about MyObject it throws an exception
stating it is unable to find the assembly.

Define an Interface-only assembly with the Interface you want your
object to implement. Both client and server will have a reference to
the interface assembly, but only the server needs a reference to the
concrete implementation assembly.

On the client, when you deserialize the object, cast it to your
interface and interact with it that way.
 
Also ensure that your object is derived from MarshalByRefObject (rather than
using the Serializable attribute or implementing the ISerializable
interface).

This ensures that your client will build a proxy to the real object on the
server rather than try to reinstantiate the object on the client side.

Paul Wardle
 
Back
Top