public static string TryResolveGACAssembly(string name, string culture, string version, string publicKeyToken) { if (String.IsNullOrEmpty(name)) { return(null); } GACAssemblyName[] matchingName = GetGACAssemblies(name); if (matchingName.Length == 0) { return(null); } if (!String.IsNullOrEmpty(publicKeyToken)) { for (int i = 0; i < matchingName.Length; i++) { if (!String.Equals(matchingName[i].PublicKeyToken, publicKeyToken, StringComparison.OrdinalIgnoreCase)) { matchingName[i] = null; } } } if (!String.IsNullOrEmpty(culture)) { for (int i = 0; i < matchingName.Length; i++) { if (matchingName[i] != null && !String.Equals(matchingName[i].Culture, culture, StringComparison.OrdinalIgnoreCase)) { matchingName[i] = null; } } } GACAssemblyName winner = null; if (!String.IsNullOrEmpty(version)) { for (int i = 0; i < matchingName.Length; i++) { if (matchingName[i] != null) { if (!String.Equals(matchingName[i].Version, version, StringComparison.OrdinalIgnoreCase)) { matchingName[i] = null; } else { winner = matchingName[i]; } } } } else { Version latest = null; for (int i = 0; i < matchingName.Length; i++) { if (matchingName[i] != null) { if (latest == null) { winner = matchingName[i]; latest = new Version(winner.Version); } else { Version compare = new Version(matchingName[i].Version); if (latest < compare) { winner = matchingName[i]; latest = compare; } } } } } if (winner == null) { return(null); } return(winner.ToString()); }