MarshalByRefObject and serialization

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

thank

+1


source to share


1 answer


Not. The idea behind MarshalByRefObject is that not everyone gets serialized for remote access purposes. Instead, the CLR generates a so-called transparent proxy in this scenario. It's called Transparent because it looks and acts the same as ClassA, but it's not really ClassA. All calls to an instance of ClassA are sorted across all remote boundaries to the original AppDomain where ClassA was created.

EDIT: Answer for further clarification.



When passing data to MarshalByRefObject in this scenario, you need to consider what type of data. Essentially derived from MarshalByRefObject, or not. If it comes out of MarshalByRefObject then the parameter will be passed as a proxy. If it is not derived from MarshalByRefObject, it will be serialized, passed across the AppDomain boundary as a series of bytes, and then rolled back to the target AppDomain.

Your script lists strings that are not MarshalByRefs (I usually call them as MarshalByValue, but that's purely a convention). Therefore, they will be serialized when they cross your remote border.

+3


source







All Articles