Search code examples
c#appdomain

How to test if code runs in other appdomain


I've written the following code to try to execute code in another appdomain, but how do I test if it actually is executed in the other appdomain?

AppDomain a = AppDomain.CreateDomain("Test");
CompilerParameters cp1 = new CompilerParameters();
string program1 = "using System; public class A{ public A(){}}";
ObjectHandle handle = a.CreateInstanceFrom(Assembly.GetExecutingAssembly().Location,     "DOTNETCOMPILERa.RommelClass");
RommelClass test = (RommelClass)handle.Unwrap();
CompilerResults cr = test.test(program1, cp1);

AppDomain.Unload(a);

Solution

  • You can e.g. evaluate the FriendlyName or the Id of AppDomain.CurrentDomain. It should return different values depending on the appdomain it runs in.