tags:

views:

701

answers:

2

When we used AppDomain.CreateInstance("Assembly name", Type name) and my class inherits from MarshalByRefObject what happen internally? Is it create a TransparetnProxy?

Code:

class Greet : MarshalByRefObejct
{
  ...
}

class test
{
 public static void Main(string[] args)
 {
   AppDomain ad = AppDomain.CreateDomain("Second");
   ObjectHandle hObj = ad.CreateInstance("Test", args[0]);
  ....
 }
}

passing in args[0] = Greet

+2  A: 

Yes, it creates a transparent proxy, which you get by unwrapping the object handle.

I find the documentation and example for ObjectHandle.Unwrap is quite informative, as is the general MarshalByRefObject documentation.

Jon Skeet
+1  A: 

Yes.

You might also want to take a look at CreateInstanceAndUnwrap. If your code in Main and the Greet class were to share a common interface, you could cast hObj into your interface and call methods on it using the TransparentProxy.

siz