Ejemplo n.º 1
0
        // If assemblyName is not fully qualified, a random matching may be
        public static String QueryAssemblyInfo(String assemblyName)
        {
            WinApi.ASSEMBLY_INFO assembyInfo = new WinApi.ASSEMBLY_INFO();
            assembyInfo.cchBuf = 512;
            assembyInfo.currentAssemblyPath = new String('\0',
                                                         assembyInfo.cchBuf);

            WinApi.IAssemblyCache assemblyCache = null;

            // Get IAssemblyCache pointer
            int hr = WinApi.CreateAssemblyCache(out assemblyCache, 0);

            if (hr == 0)
            {
                hr = assemblyCache.QueryAssemblyInfo(1, assemblyName, ref assembyInfo);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            else
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return(assembyInfo.currentAssemblyPath);
        }