System Namespace
Defines the base class for remoting objects that need to be marshalled by reference.
Some key points to classes that derive from MarshalByRefObject:
* Derive from System.MarshalByRefObject or any of its children ( except from context bound objects which derive from System.ContextBoundObject ).
* Have distributed identity.
* Instances of MarshalByRefObject classes are confined to the App Domain in which they were created, their "Home AppDomain", but are accessible directly from any context within that App Domain. An App Domain is the logical equivalent of a sub-process within the Runtime.
* MarshalByRefObject's are appropriate when the state of the object should stay in the AppDomain that created it and only references should be marshaled when the object is remoted. For example a File IO object that internally has field which is an OS handle should be made AppDomain-bound, since the OS handle would not be useful or appropriate in another AppDomain in another process or another machine.
* If a MarshalByRefObject is passed outside of the "Home AppDomain" e.g. as a parameter on a remote method call or as a return value from a remote method call, a reference is passed from the source App Domain to the target App Domain ( "Marshal By Reference" ) i.e. a reference is marshaled into the target App Domain. The following scenarios are automatically taken care of by the .NET Framework:
* Between AppDomains in the same physical process.
* Between AppDomains in different physical processes on the same machine.
* Between AppDomains in different physical processes on different machines.
* Subsequent calls on the reference in the target AppDomain are marshaled back in to the "Home AppDomain" in which the object was created.
* MarshalByRefObject's that are remoted out of the AppDomain and subsequently called remotely are called from the default context for the AppDomain.