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
a simple method to enumerate dll files in a directory
public static string[] GetGlobalAssemblyCacheFiles(string path)
{
List files = new List();
DirectoryInfo di = new DirectoryInfo(path);
foreach (FileInfo fi in di.GetFiles("*.dll"))
{
files.Add(fi.FullName);
}
foreach (DirectoryInfo diChild in di.GetDirectories())
{
var files2 = GetGlobalAssemblyCacheFiles(diChild.FullName);
files.AddRange(files2);
}
return files.ToArray();
}
and you can get all files
string gacPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Windows) + "\\assembly";
var files = GetGlobalAssemblyCacheFiles(gacPath);
If you need to load each assembly, You get a exception for different run-time version. For this reason you can load assembly with Assembly.ReflectionOnlyLoadFrom to load Assembly in reflection only. Then, Assembly don't load in your AppDomain and don't throw exception.