// See comments in UninstallAssembly public static String QueryAssemblyInfo(String assemblyName) { if (assemblyName == null) { throw new ArgumentException("Invalid name", "assemblyName"); } AssemblyInfo aInfo = new AssemblyInfo(); aInfo.cchBuf = 1024; // Get a string with the desired length aInfo.currentAssemblyPath = new String('\0', aInfo.cchBuf); IAssemblyCache ac = null; int hr = Utils.CreateAssemblyCache(out ac, 0); if (hr >= 0) { hr = ac.QueryAssemblyInfo(0, assemblyName, ref aInfo); } if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } return(aInfo.currentAssemblyPath); }
/// <summary> /// Gets information about the assembly. /// See comments in UninstallAssembly for specifying the assembly name. /// </summary> /// <param name="assemblyName"></param> /// <returns></returns> private static string QueryAssemblyInfo(String assemblyName) { if (assemblyName == null) { throw new ArgumentException("Invalid name", "assemblyName"); } AssemblyInfo aInfo = new AssemblyInfo(); aInfo.cchBuf = 1024; // Get a string with the desired length aInfo.currentAssemblyPath = new string('\0', aInfo.cchBuf); IAssemblyCache ac = null; int hr = GacUtils.CreateAssemblyCache(out ac, 0); if (hr >= 0) { hr = ac.QueryAssemblyInfo((int)QueryAssemblyInfoFlags.DEFAULT, assemblyName, ref aInfo); } if (hr == -2147024894) //File not found - This is a common error which need not be represented as an exception(ruins debug experience, also). { return(null); } else if (hr < 0) { GacUtils.ThrowMarshalledException(hr); } return(aInfo.currentAssemblyPath); }
// If assemblyName is not fully qualified, a random matching may be public static String QueryAssemblyInfo(String assemblyName) { ASSEMBLY_INFO assembyInfo = new ASSEMBLY_INFO(); assembyInfo.cchBuf = 512; assembyInfo.currentAssemblyPath = new String('\0', assembyInfo.cchBuf); IAssemblyCache assemblyCache = null; // Get IAssemblyCache pointer IntPtr hr = GacApi.CreateAssemblyCache(out assemblyCache, 0); if (hr == IntPtr.Zero) { hr = assemblyCache.QueryAssemblyInfo(1, assemblyName, ref assembyInfo); if (hr != IntPtr.Zero) { Marshal.ThrowExceptionForHR(hr.ToInt32()); } } else { Marshal.ThrowExceptionForHR(hr.ToInt32()); } return(assembyInfo.currentAssemblyPath); }
public static bool IsInGAC(AssemblyName name) { bool status; if (s_assemblyStatus.TryGetValue(name.ToString(), out status)) { return(status); } foreach (var append in s_procStringAppend) { var str = name + ", processorArchitecture=" + append; var aInfo = new AssemblyInfo(); aInfo.cbAssemblyInfo = Marshal.SizeOf(aInfo); aInfo.cchBuf = 2000; aInfo.currentAssemblyPath = new string('\0', aInfo.cchBuf); status = s_assemblyCache.QueryAssemblyInfo(0, str, ref aInfo) >= 0; if (status) { break; } } s_assemblyStatus[name.ToString()] = status; return(status); }
internal static string GetAssemblyPath(string assemblyName, out string fullName) { IAssemblyCache cache = null; ThrowOnError(NativeMethods.CreateAssemblyCache(out cache, 0)); var info = new AssemblyInfo { cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(AssemblyInfo)) }; //ProcessorArchitecture required for this call fullName = assemblyName; if (HasProcessorArchitecture(fullName)) { //getting size of string, cchBuf will be the size cache.QueryAssemblyInfo(3, fullName, ref info); } else { //try using possible proccessors foreach (string p in proccessors) { fullName = AppendProccessor(assemblyName, p); cache.QueryAssemblyInfo(3, fullName, ref info); //if no size, not found, try another proccessor if (info.cchBuf > 0) { break; } } } //if no size, not found if (info.cchBuf == 0) { return(null); } //get path info.pszCurrentAssemblyPathBuf = new string(new char[info.cchBuf]); ThrowOnError(cache.QueryAssemblyInfo(3, fullName, ref info)); return(info.pszCurrentAssemblyPathBuf); }
private static string GetLocationImpl(IAssemblyCache assemblyCache, string strongName, string targetProcessorArchitecture) { ASSEMBLY_INFO pAsmInfo = new ASSEMBLY_INFO { cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(ASSEMBLY_INFO)) }; if (targetProcessorArchitecture != null) { strongName = strongName + ", ProcessorArchitecture=" + targetProcessorArchitecture; } int hr = assemblyCache.QueryAssemblyInfo((uint)AssemblyCacheEnum.QUERYASMINFO_FLAG_VALIDATE, strongName, ref pAsmInfo); if ((Win32NTMethods.Failed(hr) && (hr != Win32NTMethods.E_INSUFFICIENT_BUFFER)) || (pAsmInfo.cbAssemblyInfo == 0)) { return(string.Empty); } pAsmInfo.pszCurrentAssemblyPathBuf = new string(new char[pAsmInfo.cchBuf]); return(!Win32NTMethods.Failed(assemblyCache.QueryAssemblyInfo(3, strongName, ref pAsmInfo)) ? pAsmInfo.pszCurrentAssemblyPathBuf : string.Empty); }
public string QueryAssemblyPath(string displayName) { AssemblyInfo info = AssemblyInfo.Create(); if (NativeMethods.SUCCESS == _native.QueryAssemblyInfo(QueryAsmInfoFlag.Validate, displayName, ref info)) { return(info.pszCurrentAssemblyPathBuf); } return(null); }
private static string GetLocationImpl(IAssemblyCache assemblyCache, string strongName, string targetProcessorArchitecture) { ASSEMBLY_INFO pAsmInfo = new ASSEMBLY_INFO { cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(ASSEMBLY_INFO)) }; if (targetProcessorArchitecture != null) { strongName = strongName + ", ProcessorArchitecture=" + targetProcessorArchitecture; } int hr = assemblyCache.QueryAssemblyInfo(3, strongName, ref pAsmInfo); if ((Microsoft.VisualStudio.TextTemplating.NativeMethods.Failed(hr) && (hr != -2147024774)) || (pAsmInfo.cbAssemblyInfo == 0)) { return(string.Empty); } pAsmInfo.pszCurrentAssemblyPathBuf = new string(new char[pAsmInfo.cchBuf]); if (Microsoft.VisualStudio.TextTemplating.NativeMethods.Failed(assemblyCache.QueryAssemblyInfo(3, strongName, ref pAsmInfo))) { return(string.Empty); } return(pAsmInfo.pszCurrentAssemblyPathBuf); }
// // If assemblyName is not fully qualified, a random matching (in reality its a highest version) may be // static string QueryAssemblyInfo(string assemblyName) { var assembyInfo = new AssemblyInfo { cchBuf = 512 }; assembyInfo.currentAssemblyPath = new String(' ', assembyInfo.cchBuf); var result = gac.QueryAssemblyInfo(1, assemblyName, ref assembyInfo); if (result != IntPtr.Zero) { Marshal.ThrowExceptionForHR(result.ToInt32()); } return(assembyInfo.currentAssemblyPath); }
public static string QueryAssemblyInfo(string assemblyName) { if (assemblyName == null) { throw new ArgumentException("Invalid argument (assemblyName)"); } AssemblyInfo aInfo = new AssemblyInfo(); aInfo.cchBuf = 1024; aInfo.currentAssemblyPath = "Path".PadLeft(aInfo.cchBuf); IAssemblyCache ac = null; COM.CheckHR(CreateAssemblyCache(out ac, 0)); COM.CheckHR(ac.QueryAssemblyInfo(0, assemblyName, ref aInfo)); return(aInfo.currentAssemblyPath); }