public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { IAssemblyEnum aEnum = null; IApplicationContext AppCtx = null; IAssemblyName aName = null; IAssemblyName pNameEnum = null; int hr; if (name != null) { hr = CreateAssemblyNameObject(out pNameEnum, name, CANOF.PARSE_DISPLAY_NAME, 0); if (hr != 0) { return; } } hr = CreateAssemblyEnum(out aEnum, null, pNameEnum, nFlag, 0); while (hr == 0) { hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0); if (hr == 0) { uint iLen = 0; IntPtr pDisplayName = (IntPtr)0; // Get the length of the string we need aName.GetDisplayName((IntPtr)0, ref iLen, 0); if (iLen > 0) { // Do some yucky memory allocating here // We need to assume that a wide character is 2 bytes. pDisplayName = Marshal.AllocHGlobal(((int)iLen + 1) * 2); aName.GetDisplayName(pDisplayName, ref iLen, 0); String sDisplayName = Marshal.PtrToStringUni(pDisplayName); Marshal.FreeHGlobal(pDisplayName); // Our info is in a comma seperated list. Let's pull it out String[] sFields = sDisplayName.Split(new char[] { ',' }); AssemblyInformation newguy = new AssemblyInformation(); newguy.FullName = sDisplayName; newguy.Name = sFields[0]; // The version string is represented as Version=###### // Let's take out the 'Version=' newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=') + 1); // Same goes for the locale newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=') + 1); // And the key token sFields[3] = sFields[3].Substring(sFields[3].IndexOf('=') + 1); if (sFields[3].Equals("null")) { sFields[3] = "null"; } newguy.PublicKeyToken = sFields[3]; alAssems.Add(newguy); } } } }
private bool GetReferenceAssembly(Assembly asm) { try { AssemblyName[] list = asm.GetReferencedAssemblies(); if (list.Length > 0) { AssemblyInformation info = null; _lstReferences = new List<AssemblyInformation>(); for (int i = 0; i < list.Length; i++) { info = new AssemblyInformation(); info.Name = list[i].Name; info.Version = list[i].Version.ToString(); info.FullName = list[i].ToString(); this._lstReferences.Add(info); } } } catch (Exception err) { this._errMsg = err.Message; return false; } return true; }
public bool GetVersion(Assembly asm) { if (asm != null) { this._info = new AssemblyInformation(); this._info.Name = asm.GetName().Name; this._info.Version = asm.GetName().Version.ToString(); this._info.FullName = asm.GetName().ToString(); } else { this._errMsg = "Invalid assembly"; return false; } return GetReferenceAssembly(asm); }
public bool GetVersion(string fileName) { Assembly asm = null; try { asm = Assembly.LoadFrom(fileName); } catch (Exception err) { this._errMsg = err.Message; return false; } if (asm != null) { this._info = new AssemblyInformation(); this._info.Name = asm.GetName().Name; this._info.Version = asm.GetName().Version.ToString(); this._info.FullName = asm.GetName().ToString(); } else { this._errMsg = "Invalid assembly"; return false; } return GetReferenceAssembly(asm); }
static private AssemblyInformation EnumerateCache(String partialName) { ArrayList a = new ArrayList(); AssemblyInformation ainfo; AssemblyInformation ainfoHighest = new AssemblyInformation(); partialName = StripVersionFromAssemblyString(partialName); Fusion.ReadCache(a, partialName, ASM_CACHE.GAC); IEnumerator myEnum = a.GetEnumerator(); while (myEnum.MoveNext()) { ainfo = (AssemblyInformation) myEnum.Current; if (ainfoHighest.Version == null) { // Use the first valid version number string[] astrVer1 = ainfo.Version.Split('.'); if(astrVer1.Length == 4) ainfoHighest = ainfo; } else { int compare = 0; if (CompareVersionString(ainfo.Version, ainfoHighest.Version, ref compare) == 0 && compare > 0) ainfoHighest = ainfo; } } return ainfoHighest; }
public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { IntPtr aEnum = IntPtr.Zero; IntPtr aName = IntPtr.Zero; IntPtr aNameEnum = IntPtr.Zero; IntPtr AppCtx = IntPtr.Zero; int hr; try { if (name != null) { hr = CreateAssemblyNameObject(out aNameEnum, name, CANOF.PARSE_DISPLAY_NAME, IntPtr.Zero); if (hr != 0) { return; } } hr = CreateAssemblyEnum(out aEnum, AppCtx, aNameEnum, nFlag, IntPtr.Zero); while (hr == 0) { hr = GetNextAssembly(aEnum, ref AppCtx, ref aName, 0); if (hr != 0) { break; } String sDisplayName = GetDisplayName(aName, 0); if (sDisplayName == null) { continue; } // Our info is in a comma seperated list. Let's pull it out String[] sFields = sDisplayName.Split(new char[] { ',' }); AssemblyInformation newguy = new AssemblyInformation(); newguy.FullName = sDisplayName; newguy.Name = sFields[0]; // The version string is represented as Version=###### // Let's take out the 'Version=' newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=') + 1); // Same goes for the locale newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=') + 1); // And the key token sFields[3] = sFields[3].Substring(sFields[3].IndexOf('=') + 1); if (sFields[3].Equals("null")) { sFields[3] = "null"; } newguy.PublicKeyToken = sFields[3]; alAssems.Add(newguy); } } finally { ReleaseFusionHandle(ref aEnum); ReleaseFusionHandle(ref aName); ReleaseFusionHandle(ref aNameEnum); ReleaseFusionHandle(ref AppCtx); } }
public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { IntPtr aEnum = IntPtr.Zero; IntPtr aName = IntPtr.Zero; IntPtr aNameEnum = IntPtr.Zero; IntPtr AppCtx = IntPtr.Zero; int hr; try { if (name != null) { hr = CreateAssemblyNameObject(out aNameEnum, name, CANOF.PARSE_DISPLAY_NAME, IntPtr.Zero); if (hr != 0) return; } hr = CreateAssemblyEnum(out aEnum, AppCtx, aNameEnum, nFlag, IntPtr.Zero); while (hr == 0) { hr = GetNextAssembly(aEnum, ref AppCtx, ref aName, 0); if (hr != 0) break; String sDisplayName = GetDisplayName(aName, 0); if (sDisplayName == null) continue; // Our info is in a comma seperated list. Let's pull it out String[] sFields = sDisplayName.Split(new char[] {','}); AssemblyInformation newguy = new AssemblyInformation(); newguy.FullName = sDisplayName; newguy.Name = sFields[0]; // The version string is represented as Version=###### // Let's take out the 'Version=' newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=')+1); // Same goes for the locale newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=')+1); // And the key token sFields[3]=sFields[3].Substring(sFields[3].IndexOf('=')+1); if (sFields[3].Equals("null")) sFields[3] = "null"; newguy.PublicKeyToken = sFields[3]; alAssems.Add(newguy); } } finally { ReleaseFusionHandle(ref aEnum); ReleaseFusionHandle(ref aName); ReleaseFusionHandle(ref aNameEnum); ReleaseFusionHandle(ref AppCtx); } }