public MFTestResults AppDomain_Test2() { MFTestResults testResult = MFTestResults.Pass; try { Log.Comment("Get and display the friendly name of the default AppDomain."); string callingDomainName = Thread.GetDomain().FriendlyName; Type Type1 = this.GetType(); string exeAssembly = Assembly.GetAssembly(Type1).FullName; Log.Comment("1. Creates an AppDomain"); AppDomain ad2 = AppDomain.CreateDomain("AppDomain #3"); TestMarshalByRefType mbrt = (TestMarshalByRefType)ad2.CreateInstanceAndUnwrap( exeAssembly, typeof(TestMarshalByRefType).FullName); ad2.Load(ad2.GetAssemblies()[0].FullName); Log.Comment("2. Calls SomeMethod in it"); mbrt.SomeMethod(callingDomainName); Log.Comment("3. Unloads that domain:"); AppDomain.Unload(ad2); Log.Comment("4. Reload AppDomain with same friendly name"); ad2 = AppDomain.CreateDomain("AppDomain #3"); mbrt = (TestMarshalByRefType)ad2.CreateInstanceAndUnwrap( exeAssembly, typeof(TestMarshalByRefType).FullName); ad2.Load(ad2.GetAssemblies()[0].FullName); Log.Comment("5. Calls SomeMethod in it"); mbrt.SomeMethod(callingDomainName); Log.Comment("6. Unloads that domain:"); AppDomain.Unload(ad2); } catch (Exception e) { Log.Comment("Generic Catch; this is bad. " + e.Message); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults AppDomain_Test1() { /// <summary> /// 1. Creates an AppDomain /// 2. Calls SomeMethod in it /// 3. Unloads that domain /// 4. Calls SomeMethod again /// 21291 Calling a method in an unloaded app domain should throw an exception. /// </summary> MFTestResults testResult = MFTestResults.Pass; Log.Comment("Get and display the friendly name of the default AppDomain."); string callingDomainName = Thread.GetDomain().FriendlyName; if (callingDomainName != AppDomain.CurrentDomain.FriendlyName) { Log.Comment("Failure : Expected '" + AppDomain.CurrentDomain.FriendlyName + "' but got '" + callingDomainName + "'"); testResult = MFTestResults.Fail; } Log.Comment(callingDomainName); Type Type1 = this.GetType(); string exeAssembly = Assembly.GetAssembly(Type1).FullName; Log.Comment("1. Creates an AppDomain"); AppDomain ad2 = AppDomain.CreateDomain("AppDomain #2"); TestMarshalByRefType mbrt = (TestMarshalByRefType)ad2.CreateInstanceAndUnwrap( exeAssembly, typeof(TestMarshalByRefType).FullName); Assembly asm4 = ad2.Load(ad2.GetAssemblies()[0].FullName); if (asm4.FullName != ad2.GetAssemblies()[0].FullName) { testResult = MFTestResults.Fail; } Log.Comment("2. Calls SomeMethod in it"); mbrt.SomeMethod(callingDomainName); Log.Comment("3. Unloads that domain:"); AppDomain.Unload(ad2); try { Log.Comment("4. calls SomeMethod again"); mbrt.SomeMethod(callingDomainName); Log.Comment("Sucessful call."); testResult = MFTestResults.Fail; } catch (AppDomainUnloadedException e) { Log.Comment("Specific Catch; this is expected. " + e.Message); } catch (Exception e) { Log.Comment("Generic Catch; this is bad. " + e.Message); testResult = MFTestResults.Fail; } return(testResult); }