/// <summary>
        ///     Finds an assembly that exactly matches the requested assembly
        /// </summary>
        /// <param name="assembly">Assembly to find</param>
        /// <param name="paths">Search paths or <c>null</c> if none</param>
        /// <param name="moduleContext">Module context</param>
        /// <returns>
        ///     An <see cref="AssemblyDef" /> instance or <c>null</c> if an exact match
        ///     couldn't be found.
        /// </returns>
        private AssemblyDef FindExactAssembly(IAssembly assembly, ThreadSafe.IEnumerable <string> paths, ModuleContext moduleContext)
        {
            if (paths == null)
            {
                return(null);
            }
            var asmComparer = AssemblyNameComparer.CompareAll;

            foreach (var path in paths.GetSafeEnumerable())
            {
                ModuleDefMD mod = null;
                try
                {
                    mod = ModuleDefMD.Load(path, moduleContext);
                    var asm = mod.Assembly;
                    if (asm != null && asmComparer.Equals(assembly, asm))
                    {
                        mod = null;
                        return(asm);
                    }
                }
                catch
                {
                }
                finally
                {
                    if (mod != null)
                    {
                        mod.Dispose();
                    }
                }
            }
            return(null);
        }
 private ThreadSafe.IEnumerable <string> FindAssemblies2(IAssembly assembly, ThreadSafe.IEnumerable <string> paths)
 {
     if (paths != null)
     {
         var asmSimpleName = UTF8String.ToSystemStringOrEmpty(assembly.Name);
         var exts          = assembly.IsContentTypeWindowsRuntime ? winMDAssemblyExtensions : assemblyExtensions;
         foreach (var ext in exts)
         {
             foreach (var path in paths.GetSafeEnumerable())
             {
                 var fullPath = Path.Combine(path, asmSimpleName + ext);
                 if (File.Exists(fullPath))
                 {
                     yield return(fullPath);
                 }
             }
         }
     }
 }
        private AssemblyDef FindClosestAssembly(IAssembly assembly, AssemblyDef closest, ThreadSafe.IEnumerable <string> paths, ModuleContext moduleContext)
        {
            if (paths == null)
            {
                return(closest);
            }
            var asmComparer = AssemblyNameComparer.CompareAll;

            foreach (var path in paths.GetSafeEnumerable())
            {
                ModuleDefMD mod = null;
                try
                {
                    mod = ModuleDefMD.Load(path, moduleContext);
                    var asm = mod.Assembly;
                    if (asm != null && asmComparer.CompareClosest(assembly, closest, asm) == 1)
                    {
                        if (!IsCached(closest) && closest != null)
                        {
                            var closeMod = closest.ManifestModule;
                            if (closeMod != null)
                            {
                                closeMod.Dispose();
                            }
                        }
                        closest = asm;
                        mod     = null;
                    }
                }
                catch
                {
                }
                finally
                {
                    if (mod != null)
                    {
                        mod.Dispose();
                    }
                }
            }

            return(closest);
        }