/// <summary> /// Initialize the AppDomain and load the types of the dll /// </summary> /// <returns>the types of the dll</returns> public void CreateAppDomain() { string currentDirectory = Environment.CurrentDirectory; string cachePath = Path.Combine( currentDirectory, "__cache"); PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted); AppDomainSetup appDomainSetup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, ShadowCopyFiles = "true", CachePath = cachePath }; _testsDomain = AppDomain.CreateDomain("TestDomain", null, appDomainSetup, permissionSet); try { ITypesLoaderFactory typesLoaderFactory = (ITypesLoaderFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, " RegTesting.Tests.Core.TypesLoaderFactory").Unwrap(); object[] constructArgs = new object[] { }; ITypesLoader typesLoader = typesLoaderFactory.Create(Assembly.GetExecutingAssembly().FullName, " RegTesting.Tests.Core.TypesLoader", constructArgs); Types = typesLoader.GetTypes(_testsFile); } catch (NullReferenceException) { } }
/// <summary> /// Initialize the AppDomain and load the types of the dll /// </summary> /// <returns>the types of the dll</returns> public string[] LoadTypes() { string environmentPath = Environment.CurrentDirectory; string cachePath = Path.Combine(environmentPath, "__cache"); PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted); AppDomainSetup appDomainSetup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, ShadowCopyFiles = "true", CachePath = cachePath }; _testsDomain = AppDomain.CreateDomain("TestDomain", null, appDomainSetup, permissionSet); try { ITypesLoaderFactory typesLoaderFactory = (ITypesLoaderFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TypesLoaderFactory").Unwrap(); object[] constructArgs = new object[] {}; ITypesLoader typesLoader = typesLoaderFactory.Create(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TypesLoader", constructArgs); Types = typesLoader.GetTypes(_testsFile); foreach (string type in Types) { if (type.StartsWith("ERROR:")) { Console.WriteLine(type); } } return(Types); } catch (NullReferenceException) { //No types found for this branch return(new string[0]); } catch (ReflectionTypeLoadException reflectionTypeLoadException) { StringBuilder stringBuilder = new StringBuilder(); foreach (Exception exSub in reflectionTypeLoadException.LoaderExceptions) { stringBuilder.AppendLine(exSub.Message); if (exSub is FileNotFoundException) { FileNotFoundException fileNotFoundException = exSub as FileNotFoundException; if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog)) { stringBuilder.AppendLine("Fusion Log:"); stringBuilder.AppendLine(fileNotFoundException.FusionLog); } } stringBuilder.AppendLine(); } string errorMessage = stringBuilder.ToString(); Console.WriteLine(errorMessage); //Display or log the error based on your application. return(new string[0]); } catch (Exception exception) { Console.WriteLine(exception.ToString()); //No types found for this branch return(new string[0]); } }