How can I enumerate all available assemblies in GAC in C#?
Actually I am facing an issue with a stupid code - the assembly called Telerik.Web.UI.dll is referred and
Figure i might as well throw in my linq based solution (handy if your just looking for a single file and don't want to enumerate through every file)
function to find the files:
public static IEnumerable FindFiles (string path, string filter = "", int depth = int.MaxValue) {
DirectoryInfo di = new DirectoryInfo(path);
IEnumerable results = (! string.IsNullOrEmpty(filter) ? di.GetFiles(filter) : di.GetFiles()).Select(f => f.FullName);
if (depth > 0) {
results = results.Concat(di.GetDirectories().SelectMany(d => FindFiles(d.FullName, filter, depth - 1)));
}
return results;
}
And to call (i didn't have Environment.SpecialFolder.Windows so used Environment.SpecialFolder.System instead)
string path = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\..\\assembly";
foreach (string s in FindFiles(path, "*.dll")) {
Console.WriteLine(s);
}
Further, as a FYI this method enumerates the entire GAC and you may find duplicate DLLs in tmp/ and temp/, Tmp is used for installation, and Temp is used for uninstallation.