Exemple #1
0
        /// <summary>
        /// Returns the original location of the corresponding assembly if available, otherwise returns the location of the shadow copy.
        /// If the corresponding assembly is not in the GAC, null is returned.
        /// </summary>
        public static string /*?*/ GetLocation(AssemblyIdentity assemblyIdentity, IMetadataHost metadataHost)
        {
            lock (GlobalLock.LockingObject) {
#if COMPACTFX
                var gacKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global");
                foreach (var gacName in gacKey.GetValueNames())
                {
                    if (IdentityMatchesString(assemblyIdentity, gacName))
                    {
                        var values = gacKey.GetValue(gacName) as string[];
                        if (values == null || values.Length == 0)
                        {
                            continue;
                        }
                        return(values[0]);
                    }
                }
                return(null);
#elif COREFX_SUBSET
                return(null);
#else
#if __MonoCS__
                IAssemblyEnum assemblyEnum = new MonoAssemblyEnum();
#else
                if (!GlobalAssemblyCache.FusionLoaded)
                {
                    GlobalAssemblyCache.FusionLoaded = true;
                    var systemAssembly         = typeof(object).Assembly;
                    var systemAssemblyLocation = systemAssembly.Location;
                    var dir = Path.GetDirectoryName(systemAssemblyLocation) ?? "";
                    GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll"));
                }
                IAssemblyEnum assemblyEnum;
                int           rc = CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0);
                if (rc < 0 || assemblyEnum == null)
                {
                    return(null);
                }
#endif
                IApplicationContext applicationContext;
                IAssemblyName       currentName;
                while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0)
                {
                    //^ assume currentName != null;
                    AssemblyName cn = new AssemblyName(currentName);
                    if (assemblyIdentity.Equals(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(cn.Name), cn.Culture, cn.Version, cn.PublicKeyToken, "")))
                    {
                        string codeBase = cn.CodeBase;
                        if (codeBase != null && codeBase.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
                        {
                            Uri u = new Uri(codeBase, UriKind.Absolute);
                            return(u.LocalPath);
                        }
                        return(cn.GetLocation());
                    }
                }
                return(null);
#endif
            }
        }
 /// <summary>
 /// Returns the original location of the corresponding assembly if available, otherwise returns the location of the shadow copy.
 /// If the corresponding assembly is not in the GAC, null is returned.
 /// </summary>
 public static string /*?*/ GetLocation(AssemblyIdentity assemblyIdentity, IMetadataHost metadataHost)
 {
     lock (GlobalLock.LockingObject)
     {
         if (!GlobalAssemblyCache.s_fusionLoaded)
         {
             GlobalAssemblyCache.s_fusionLoaded = true;
             System.Reflection.Assembly systemAssembly = typeof(object).Assembly;
             //^ assume systemAssembly != null;
             string /*?*/ systemAssemblyLocation = systemAssembly.Location;
             //^ assume systemAssemblyLocation != null;
             string dir = Path.GetDirectoryName(systemAssemblyLocation);
             //^ assume dir != null;
             GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll"));
         }
         IAssemblyEnum assemblyEnum;
         CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0);
         if (assemblyEnum == null)
         {
             return(null);
         }
         IApplicationContext applicationContext;
         IAssemblyName       currentName;
         while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0)
         {
             //^ assume currentName != null;
             AssemblyName assemblyName = new AssemblyName(currentName);
             string /*?*/ location     = assemblyName.GetLocation();
             if (location == null)
             {
                 location = string.Empty;
             }
             if (assemblyIdentity.Equals(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(assemblyName.Name), assemblyName.Culture, assemblyName.Version, assemblyName.PublicKeyToken, location)))
             {
                 string codeBase = assemblyName.CodeBase;
                 if (codeBase != null && codeBase.StartsWith("file:///"))
                 {
                     return(codeBase.Substring(8));
                 }
                 return(assemblyName.GetLocation());
             }
         }
         return(null);
     }
 }
    /// <summary>
    /// Returns the original location of the corresponding assembly if available, otherwise returns the location of the shadow copy.
    /// If the corresponding assembly is not in the GAC, null is returned.
    /// </summary>
    public static string/*?*/ GetLocation(AssemblyIdentity assemblyIdentity, IMetadataHost metadataHost) {
      lock (GlobalLock.LockingObject) {
#if COMPACTFX
        var gacKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global");
        foreach (var gacName in gacKey.GetValueNames()) {
          if (IdentityMatchesString(assemblyIdentity, gacName)) {
            var values = gacKey.GetValue(gacName) as string[];
            if (values == null || values.Length == 0) continue;
            return values[0];
          }
        }
        return null;
#else
#if __MonoCS__
        IAssemblyEnum assemblyEnum = new MonoAssemblyEnum();
#else
        if (!GlobalAssemblyCache.FusionLoaded) {
          GlobalAssemblyCache.FusionLoaded = true;
          var systemAssembly = typeof(object).Assembly;
          var systemAssemblyLocation = systemAssembly.Location;
          var dir = Path.GetDirectoryName(systemAssemblyLocation)??"";
          GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll"));
        }
        IAssemblyEnum assemblyEnum;
        int rc = CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0);
        if (rc < 0 || assemblyEnum == null) return null;
#endif
        IApplicationContext applicationContext;
        IAssemblyName currentName;
        while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0) {
          //^ assume currentName != null;
          AssemblyName cn = new AssemblyName(currentName);
          if (assemblyIdentity.Equals(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(cn.Name), cn.Culture, cn.Version, cn.PublicKeyToken, ""))) {
            string codeBase = cn.CodeBase;
            if (codeBase != null && codeBase.StartsWith("file://", StringComparison.OrdinalIgnoreCase)) {
              Uri u = new Uri(codeBase, UriKind.Absolute);
              return u.LocalPath;
            }
            return cn.GetLocation();
          }
        }
        return null;
#endif
      }
    }