I create an AppDomain, create an instance of an object in the new Domain and call a method that returns the name of the current AppDomain on the wrapped object. the returned value is the name of the main program domain and not the newly created one. By the way the code is being executed as a UnitTest in VS2010.
Any Idea why the test fails?
[Serializable]
public class DomainHelper
{
public string GetDomainName()
{
return AppDomain.CurrentDomain.FriendlyName;
}
}
[TestClass]
public class DomainTests
{
[TestMethod]
public void RemoteCall()
{
var binDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
const string appDomainName = "TEST";
var x = AppDomain.CreateDomain(appDomainName, null, binDir,null, false);
var remoteType = typeof(DomainHelper);
var remote = (DomainHelper) x.CreateInstanceAndUnwrap(remoteType.Assembly.FullName, remoteType.FullName);
Assert.AreEqual(appDomainName, remote.GetDomainName());
}
}