private void CreateAssemblyManager(IEnumerable <ModuleData> compilationDependencies, ModuleData mainModule) { var allModules = compilationDependencies; if (_additionalDependencies != null) { allModules = allModules.Concat(_additionalDependencies); } // We need to add the main module so that it gets checked against already loaded assembly names. // If an assembly is loaded directly via PEVerify(image) another assembly of the same full name // can't be loaded as a dependency (via Assembly.ReflectionOnlyLoad) in the same domain. if (mainModule != null) { allModules = allModules.Concat(new[] { mainModule }); } allModules = allModules.ToArray(); string conflict = DetectNameCollision(allModules); if (conflict != null && !CLRHelpers.IsRunningOnMono()) { Type appDomainProxyType = typeof(RuntimeAssemblyManager); Assembly thisAssembly = appDomainProxyType.Assembly; AppDomain appDomain = null; RuntimeAssemblyManager manager; try { appDomain = AppDomain.CreateDomain("HostedRuntimeEnvironment", null, AppDomain.CurrentDomain.BaseDirectory, null, false); manager = (RuntimeAssemblyManager)appDomain.CreateInstanceAndUnwrap(thisAssembly.FullName, appDomainProxyType.FullName); } catch { if (appDomain != null) { AppDomain.Unload(appDomain); } throw; } _domain = appDomain; _assemblyManager = manager; } else { _assemblyManager = new RuntimeAssemblyManager(); } _assemblyManager.AddModuleData(allModules); if (mainModule != null) { _assemblyManager.AddMainModuleMvid(mainModule.Mvid); } }