查询的x64 GAC [英] Querying the x64-GAC

查看:163
本文介绍了查询的x64 GAC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过以​​下code,我查询了GAC,看看是否有安装我是一定的组装。 C本身的$ C $工作正常,但我只得到的结果为 86 GAC 。该组件被安装在两个GACS GAC_64和GAC_32。

什么我必须这样做,这就是QueryAssemblyInfo检查64 GAC?

 公共BOOL IsInGac(字符串的AssemblyName)
  {
     ASSEMBLY_INFO assembyInfo =新ASSEMBLY_INFO();
     assembyInfo.cchBuf = 512;
     assembyInfo.currentAssemblyPath =新的字符串('\ 0',assembyInfo.cchBuf);

     IAssemblyCache assemblyCache = NULL;

     IntPtr的HR = NativeMethods.CreateAssemblyCache(出assemblyCache,0);
     如果(小时== IntPtr.Zero)
     {
        HR = assemblyCache.QueryAssemblyInfo(1,的AssemblyName,裁判assembyInfo);
        如果(小时!= IntPtr.Zero)
        {
           返回false;
        }

        返回true;
     }

     返回false;
  }

  内部静态类NativeMethods
  {
     [的DllImport(fusion.dll)]
     公共静态外部的IntPtr CreateAssemblyCache(出IAssemblyCache ppAsmCache,INT保留);
  }

  [ComImport,InterfaceType(ComInterfaceType.InterfaceIsIUnknown)的Guid(e707dcde-d1cd-11D2-bab9-00c04f8eceae)]
  内部接口IAssemblyCache
  {
     INT Dummy1();
     [preserveSig]
     IntPtr的QueryAssemblyInfo(INT标志,[的MarshalAs(UnmanagedType.LPWStr)字符串的AssemblyName,裁判ASSEMBLY_INFO集信息);
     INT Dummy2();
     INT Dummy3();
     INT Dummy4();
  }

  [StructLayout(LayoutKind.Sequential)
  内部结构ASSEMBLY_INFO
  {
     公众诠释cbAssemblyInfo;
     公众诠释assemblyFlags;
     众长assemblySizeInKB;

     [的MarshalAs(UnmanagedType.LPWStr)
     公共字符串currentAssemblyPath;

     公众诠释cchBuf;
  }
 

解决方案

  [的DllImport(fusion.dll)
    公共静态外部的IntPtr CreateAssemblyCache(...)
 

该函数的返回类型为HRESULT。这是一个 INT ,不是的IntPtr在C#。同样的事情在QueryAssemblyInfo()声明。

这可能导致随机故障时,你的目标值为anycpu。除此之外,在code是罚款,它有没有很难找到在GAC_64组件我的机器上。

With the following code I'm querying the GAC to see if there is a certain assembly installed i it. The code itself works fine, but I only get the result for the x86 GAC. The assembly is installed in both GACs GAC_64 and GAC_32.

What do I have to do so that 'QueryAssemblyInfo' checks the x64 GAC?

  public bool IsInGac(string assemblyName)
  {
     ASSEMBLY_INFO assembyInfo = new ASSEMBLY_INFO();
     assembyInfo.cchBuf = 512;
     assembyInfo.currentAssemblyPath = new string('\0', assembyInfo.cchBuf);

     IAssemblyCache assemblyCache = null;

     IntPtr hr = NativeMethods.CreateAssemblyCache(out assemblyCache, 0);
     if (hr == IntPtr.Zero)
     {
        hr = assemblyCache.QueryAssemblyInfo(1, assemblyName, ref assembyInfo);
        if (hr != IntPtr.Zero)
        {
           return false;
        }

        return true;
     }

     return false;
  }

  internal static class NativeMethods
  {
     [DllImport("fusion.dll")]
     public static extern IntPtr CreateAssemblyCache(out IAssemblyCache ppAsmCache, int reserved);
  }

  [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("e707dcde-d1cd-11d2-bab9-00c04f8eceae")]
  internal interface IAssemblyCache
  {
     int Dummy1();
     [PreserveSig]
     IntPtr QueryAssemblyInfo(int flags, [MarshalAs(UnmanagedType.LPWStr)]string assemblyName, ref ASSEMBLY_INFO assemblyInfo);
     int Dummy2();
     int Dummy3();
     int Dummy4();
  }

  [StructLayout(LayoutKind.Sequential)]
  internal struct ASSEMBLY_INFO
  {
     public int cbAssemblyInfo;
     public int assemblyFlags;
     public long assemblySizeInKB;

     [MarshalAs(UnmanagedType.LPWStr)]
     public String currentAssemblyPath;

     public int cchBuf;
  }

解决方案

    [DllImport("fusion.dll")]
    public static extern IntPtr CreateAssemblyCache(...)

The return type for this function is HRESULT. Which is an int, not IntPtr in C#. Same thing on the QueryAssemblyInfo() declaration.

This could cause random failure when you target AnyCPU. Other than that the code is fine and it has no trouble finding assemblies in GAC_64 on my machine.

这篇关于查询的x64 GAC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆