How to configure to create the Domain in-process ??

Feb 14, 2014 at 11:45 PM
We have some classes that sometimes we need to load in-process, and other times in the external EXE.
Is there a way to create the new AppDomain inside the current EXE process? and do not spawn a new EXE.

Feb 28, 2014 at 5:47 PM
Edited Feb 28, 2014 at 5:47 PM
Yes, but in that scenario, you would strictly only use AppDomain, not ProcessDomain, and they're not easily interchangeable in that sense, unless you write your own wrapper around it. The semantics for creating an AppDomain are (purposely) similar to creating a ProcessDomain:
// AppDomainSetup is optional, if you want to pass some additional setup params, such as the config file the AppDomain will use
var setup = new AppDomainSetup()
                     // use the same config file as current (usually default) AppDomain
                     ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

AppDomain domain = AppDomain.CreateDomain("friendlyName", null, setup);

// now same way as ProcessDomain, you can create remote object instances:

var remoteObject = (MyRemoteObject) domain.CreateInstanceAndUnwrap(typeof(MyRemoteObject).Assembly.FullName, typeof(MyRemoteObject).FullName);
Whether you use AppDomain or ProcessDomain to create the remote object, what you should get back is always a Remoting Proxy that should behave the same way.