Assembly AssemblyResolve(object sender, ResolveEventArgs e) { AssemblyName name = new AssemblyName(e.Name); LoggingService.Debug("ProjectContentRegistry.AssemblyResolve " + e.Name); string path = Path.Combine(lookupDirectory, name.Name); if (File.Exists(path + ".dll")) { return(Assembly.ReflectionOnlyLoadFrom(path + ".dll")); } if (File.Exists(path + ".exe")) { return(Assembly.ReflectionOnlyLoadFrom(path + ".exe")); } if (File.Exists(path)) { return(Assembly.ReflectionOnlyLoadFrom(path)); } try { LoggingService.Debug("AssemblyResolve trying ReflectionOnlyLoad"); return(Assembly.ReflectionOnlyLoad(e.Name)); } catch (FileNotFoundException) { LoggingService.Warn("AssemblyResolve: ReflectionOnlyLoad failed for " + e.Name); // We can't get the assembly we want. // But propably we can get a similar version of it. GacAssemblyName fixedName = GacInterop.FindBestMatchingAssemblyName(e.Name); LoggingService.Info("AssemblyResolve: FixedName: " + fixedName); return(Assembly.ReflectionOnlyLoad(fixedName.FullName)); } }
public static Assembly ReflectionLoadGacAssembly(string partialName, bool reflectionOnly) { if (reflectionOnly) { GacAssemblyName name = GacInterop.FindBestMatchingAssemblyName(partialName); if (name == null) { return(null); } return(Assembly.ReflectionOnlyLoad(name.FullName)); } else { #pragma warning disable 618 return(Assembly.LoadWithPartialName(partialName)); #pragma warning restore 618 } }