private void LoadTargetLibAssembly() { var targetLibLocation = Path.GetFullPath(Path.Combine(AssemblyLocater.GetGaugeBinDir(), string.Concat(GaugeLibAssembleName, ".dll"))); var logger = LogManager.GetLogger("AssemblyLoader"); if (!_fileWrapper.Exists(targetLibLocation)) { var message = string.Format("Unable to locate Gauge Lib at: {0}", targetLibLocation); logger.Error(message); throw new FileNotFoundException(message); } _targetLibAssembly = _assemblyWrapper.LoadFrom(targetLibLocation); var targetLibVersion = _targetLibAssembly.GetName().Version; if (targetLibVersion <= _minimumLibversion) { throw new GaugeLibVersionMismatchException(targetLibVersion, _minimumLibversion); } logger.Debug("Target Lib loaded : {0}, from {1}", _targetLibAssembly.FullName, _targetLibAssembly.Location); }
public AssemblyLoader(string runnerBasePath, IAssemblyWrapper assemblyWrapper, IFileWrapper fileWrapper, IEnumerable <string> assemblyLocations) { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var logger = LogManager.GetLogger("AssemblyLoader"); logger.Debug("Loading {0}", args.Name); try { var assemblyName = args.Name.Split(',').FirstOrDefault(); var gaugeBinDir = AssemblyLocater.GetGaugeBinDir(); var probePath = Path.GetFullPath(Path.Combine(gaugeBinDir, string.Format("{0}.dll", assemblyName))); if (File.Exists(probePath)) { return(Assembly.LoadFrom(probePath)); } probePath = Path.GetFullPath(Path.Combine(runnerBasePath, string.Format("{0}.dll", assemblyName))); if (File.Exists(probePath)) { return(Assembly.LoadFrom(probePath)); } var executingAssembly = Assembly.GetExecutingAssembly(); return(executingAssembly.GetName().Name == assemblyName ? executingAssembly : null); } catch (Exception e) { logger.Error(e); return(null); } }; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, args) => { var logger = LogManager.GetLogger("AssemblyLoader"); logger.Debug("Reflection only Loading {0}", args.Name); try { var assemblyName = args.Name.Split(',').FirstOrDefault(); var gaugeBinDir = AssemblyLocater.GetGaugeBinDir(); var probePath = Path.GetFullPath(Path.Combine(gaugeBinDir, string.Format("{0}.dll", assemblyName))); if (File.Exists(probePath)) { return(Assembly.ReflectionOnlyLoadFrom(probePath)); } probePath = Path.GetFullPath(Path.Combine(runnerBasePath, string.Format("{0}.dll", assemblyName))); return(File.Exists(probePath) ? Assembly.ReflectionOnlyLoadFrom(probePath) : null); } catch (Exception e) { logger.Error(e); return(null); } }; _assemblyWrapper = assemblyWrapper; _fileWrapper = fileWrapper; LoadTargetLibAssembly(); AssembliesReferencingGaugeLib = new List <Assembly>(); ScreengrabberTypes = new List <Type>(); ClassInstanceManagerTypes = new List <Type>(); foreach (var location in assemblyLocations) { ScanAndLoad(location); } }