Issues with Cloning MarshalByRefObject

Cloning MarshalByRefObjects can lead to some unexpected behaviour. When a MBR object is marshalled, it gets an unique identity which contains a unique URI to identify this object in the appdomain. When an external call is made to this object it is identified by this URI. An identity once created doesnt change each time the object is marshalled. Now if an MBR object with its identity set is cloned using Object.MemberwiseClone(since this deep clones all private/public fields as well) the cloned object would get the same identity. If the clone is marshalled out, wouldnt get a new identity since it already has one. Thus if calls are made to the cloned object, the invocation could actually be done on the original object, which could lead to some really unwanted results. So please be extra careful while cloning MBRs when the cloned object could potentially be marshalled as well.

In v2.0 of the framework, MBR probably would have a clone helper which would null out the identity after cloning.