public void LocateAssemblyOnAssemblyLoadFailure() { var assemblies = new Dictionary <string, Assembly> { { GetAssemblyPath(typeof(string).Assembly), typeof(string).Assembly }, { GetAssemblyPath(typeof(SetUpAttribute).Assembly), typeof(SetUpAttribute).Assembly }, { GetAssemblyPath(Assembly.GetExecutingAssembly()), Assembly.GetExecutingAssembly() }, }; Func <IEnumerable <string> > assemblyNameResolver = () => assemblies.Keys.ToArray(); var helper = new FusionHelper(assemblyNameResolver); helper.AssemblyLoader = (assemblyPath) => { return(assemblies[assemblyPath]); }; AppDomain.CurrentDomain.AssemblyResolve += helper.LocateAssemblyOnAssemblyLoadFailure; var name = Assembly.GetExecutingAssembly().GetName().Name; var result = helper.LocateAssemblyOnAssemblyLoadFailure(null, new ResolveEventArgs(name)); Assert.AreSame(Assembly.GetExecutingAssembly(), result); }
/// <summary> /// Attaches the assembly resolution method to the <see cref="AppDomain.AssemblyResolve"/> /// event of the current <see cref="AppDomain"/>. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown when <see cref="FileBasedResolver.StoreFilePaths"/> has not been called prior to /// attaching the directory resolver to an <see cref="AppDomain"/>. /// </exception> public void Attach() { var domain = AppDomain.CurrentDomain; { var helper = new FusionHelper(() => _files); domain.AssemblyResolve += helper.LocateAssemblyOnAssemblyLoadFailure; } }
/// <summary> /// Attaches the assembly resolution method to the <see cref="AppDomain.AssemblyResolve"/> /// event of the current <see cref="AppDomain"/>. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown when <see cref="FileBasedResolver.StoreFilePaths"/> has not been called prior to /// attaching the directory resolver to an <see cref="AppDomain"/>. /// </exception> public void Attach() { { Lokad.Enforce.NotNull(() => m_Files); } var domain = AppDomain.CurrentDomain; { var helper = new FusionHelper(() => m_Files); domain.AssemblyResolve += helper.LocateAssemblyOnAssemblyLoadFailure; } }
/// <summary> /// Attaches the assembly resolution method to the <see cref="AppDomain.AssemblyResolve"/> /// event of the current <see cref="AppDomain"/>. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown when <see cref="DirectoryBasedResolver.StoreDirectoryPaths"/> has not been called prior to /// attaching the directory resolver to an <see cref="AppDomain"/>. /// </exception> public void Attach() { var domain = AppDomain.CurrentDomain; { var helper = new FusionHelper( () => _directories.SelectMany( dir => Directory.GetFiles( dir, "*.dll", SearchOption.AllDirectories))); domain.AssemblyResolve += helper.LocateAssemblyOnAssemblyLoadFailure; } }