tags:

views:

566

answers:

2

When I create a class, say ClassA, that inherits from MarshalByRefObject and then use the RemotingServices.Marshal method to create an ObjRef object does it serialize the all the private fields of ClassA?

Thanks

+1  A: 

No. The idea of MarshalByRefObject is that it doesn't every get serialized for remoting purposes. Instead the CLR generates what is known as a transparent proxy in this scenario. It's called Transparent because it looks and acts just like ClassA but in reality is not actually ClassA. All calls into an instance of ClassA are marshalled accross the remoting boundaries into the original AppDomain where ClassA was created.

EDIT: Responding to further clarification.

When passing data to a MarshalByRefObject in this scenario you need to consider what type the data is. Essentially derives from MarshalByRefObject or it doesn't. If it does derive from MarshalByRefObject then the parameter will be passed as a proxy. If it doesn't derive from MarshalByRefObject then it will be serialized, passed across the AppDomain boundary as a series of bytes and then deseriazied in the target AppDomain.

Your scenario listed strings which are not MarshalByRef (usually I refer to these as MarshalByValue but that's purely convention). So they will be serialized when passed across your remoting boundary.

JaredPar
A: 

so if i have a large class (lots of state) and use RemotingServices.Marshal to get a proxy and then send that proxy over TCP (remoting boundary) the objects state won't get serialized?

And then, in another appdomain (another machine on the network) a method on the proxy is given a large amount of data , say a large list of strings, where will the data be processed? In the proxy or the orginal obect? Or will the proxy just send the data to the original object?

Thanks

The data will be marshalled to where the original object resides, everything will be processed by this object. The proxy just forwards the calls, no less no more.
liggett78