Link to home
Start Free TrialLog in
Avatar of uttam80
uttam80

asked on

Marshalling

I am experimenting with with 'Marshall by Value' using C#.
I have written a client which uses a interface to remote object
e.g. iRemobj.ReadFile(filename);

Implemantation of this interface I have done on the server side
e.g. class/file name 'RemObj'

Now when I try  'iRemobj.ReadFile(filename)' It executes only when a copy of implementation file 'RemObj.dll' is also available with the client otherwise it generates exceptions as attached below.

So the question is
Is it necessary to have implementation file of remote serializable object with the client ?
If yes then is there any workaround for this ?

Regards
Uttam

[e] An exception occurred.
System.Runtime.Serialization.SerializationException: Cannot find the assembly RemoteObjectMBV, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
[ remaining lines ommited... ]

Avatar of drichards
drichards

>> Is it necessary to have implementation file of remote serializable object with the client ?
Yes, that is what marshal-by-value does.  You need to have the implementation of the object on both ends because "marshal-by-value" means "move the whole object to the other end".  So if your client calls a remote method that returns a "marshal-by-value" object, the client must have the executable for that object.  If the client passes a "marshal-by-value" object to the server, the server must have the implementation of the object.

>> If yes then is there any workaround for this ?
No.  Well, actually the workaround is don't use marshal-by-value.
It has been awhile since I used the remoting, however from what I remember you can sirialize an object with a binary serializer.  However, to avoid having to have the assembly in both the client and server you can create an interface that the class implements.  Then you can cast the class to the interface and serialize the interface.  Then only the interface needs to be available to both the client and server.  This is because when an object is deserialized it has to deserialize into the exact object that it was serialized from, at least this is my understanding.

Hope this helps,
nipnfriar_tuck
You can do custom marshaling to get other results, but if you are doing marshal-by-value you MUST have the complete implementation of the object to make it work because the receiving end must instantiate a copy of the object.  This is useful for the same reason you pass parameters by value rather than by reference in C++ or any other language.  Passing by value means you have a local copy of the value that you can change without affecting the original value.  To do that with an object, though, you need the complete implementation including any supporting objects/functions that the object may use.

Another reason you might marshal by value is that you are going to use the object a lot and it is easier just to send the whole object to the client and do all the processing locally as opposed to sending all the method calls over the wire.  Of course you need to send the object back to the server if the server cares about the modified version of the object.
Avatar of uttam80

ASKER

Just additional information.

1. Hello nipnfriar_tuck,
On client I am using the interface and the class implementation is on the server. Ofcourse I am also forced to copy the same class implementation on the client and thats the problem I am discussing about.

2. I was comparing this feature with java, I there with RMI ( similar to Remoting in .Net ) does not force serializable class to be physically copied on the client system. On client we can use its interface.

So all these features are very crusial in our decision making on .NET . Any help ?

Uttam


ASKER CERTIFIED SOLUTION
Avatar of NipNFriar_Tuck
NipNFriar_Tuck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial