Gert Kommer Gert Kommer - 8 months ago 69
C# Question

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);


Answer Source

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.