public override AssemblyIdentity ResolvePartialName( string displayName, out string location, ImmutableArray <ProcessorArchitecture> architectureFilter, CultureInfo preferredCulture) { if (displayName == null) { throw new ArgumentNullException(nameof(displayName)); } location = null; FusionAssemblyIdentity.IAssemblyName nameObject = FusionAssemblyIdentity.ToAssemblyNameObject(displayName); if (nameObject == null) { return(null); } var candidates = GetAssemblyObjects(nameObject, architectureFilter); string cultureName = (preferredCulture != null && !preferredCulture.IsNeutralCulture) ? preferredCulture.Name : null; var bestMatch = FusionAssemblyIdentity.GetBestMatch(candidates, cultureName); if (bestMatch == null) { return(null); } location = GetAssemblyLocation(bestMatch); return(FusionAssemblyIdentity.ToAssemblyIdentity(bestMatch)); }
/// <summary> /// Looks up specified partial assembly name in the GAC and returns the best matching full assembly name/>. /// </summary> /// <param name="displayName">The display name of an assembly</param> /// <param name="location">Full path name of the resolved assembly</param> /// <param name="architectureFilter">The optional processor architecture</param> /// <param name="preferredCulture">The optional preferred culture information</param> /// <returns>An assembly identity or null, if <paramref name="displayName"/> can't be resolved.</returns> /// <exception cref="ArgumentNullException"><paramref name="displayName"/> is null.</exception> public static unsafe string ResolvePartialName( string displayName, out string location, ProcessorArchitecture[] architectureFilter = null, CultureInfo preferredCulture = null) { if (displayName == null) { throw new ArgumentNullException("displayName"); } location = null; FusionAssemblyIdentity.IAssemblyName nameObject = FusionAssemblyIdentity.ToAssemblyNameObject(displayName); if (nameObject == null) { return(null); } var candidates = GetAssemblyObjects(nameObject, architectureFilter); string cultureName = (preferredCulture != null && !preferredCulture.IsNeutralCulture) ? preferredCulture.Name : null; var bestMatch = FusionAssemblyIdentity.GetBestMatch(candidates, cultureName); if (bestMatch == null) { return(null); } string fullName = FusionAssemblyIdentity.GetDisplayName(bestMatch, FusionAssemblyIdentity.ASM_DISPLAYF.FULL); fixed(char *p = new char[MAX_PATH]) { ASSEMBLY_INFO info = new ASSEMBLY_INFO { cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(ASSEMBLY_INFO)), pszCurrentAssemblyPathBuf = p, cchBuf = (uint)MAX_PATH }; IAssemblyCache assemblyCacheObject; CreateAssemblyCache(out assemblyCacheObject, 0); assemblyCacheObject.QueryAssemblyInfo(0, fullName, ref info); Debug.Assert(info.pszCurrentAssemblyPathBuf != null); Debug.Assert(info.pszCurrentAssemblyPathBuf[info.cchBuf - 1] == '\0'); var result = Marshal.PtrToStringUni((IntPtr)info.pszCurrentAssemblyPathBuf, (int)info.cchBuf - 1); Debug.Assert(result.IndexOf('\0') == -1); location = result; } return(fullName); }
private static AssemblyIdentity ResolvePartialName( string displayName, Func <ProcessorArchitecture, bool> architectureFilter, CultureInfo preferredCulture, out string location, bool resolveLocation) { if (displayName == null) { throw new ArgumentNullException("displayName"); } location = null; FusionAssemblyIdentity.IAssemblyName nameObject = FusionAssemblyIdentity.ToAssemblyNameObject(displayName); if (nameObject == null) { return(null); } var candidates = GetAssemblyObjects(nameObject, architectureFilter); string cultureName = (preferredCulture != null && !preferredCulture.IsNeutralCulture) ? preferredCulture.Name : null; var bestMatch = FusionAssemblyIdentity.GetBestMatch(candidates, cultureName); if (bestMatch == null) { return(null); } if (resolveLocation) { location = GetAssemblyLocation(bestMatch); } return(null); //return FusionAssemblyIdentity.ToAssemblyIdentity(bestMatch); }