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
If it's plain-jane ASP.NET site, and the assembly is not in the site's bin folder or in the server's GAC (and there is nothing fishy in the web.config), perhaps the site is a sub-site of some sort and one of the site's higher up contains the reference in the bin folder (or something fishy in its web.config, since sub-sites/folders inherit the web.configs of their parents)?
Now, if you have an environment where the file is being loaded correctly (and it sounds like you do), you can just ask .NET where the .dll is coming from and display that instead, for example:
Assembly a = Assembly.Load("Microsoft.VisualStudio.Shell, Version=2.0.0.0, "
+ "PublicKeyToken=b03f5f7f11d50a3a, Culture=Neutral");
Console.WriteLine(a.Location);
Will load an assembly and display its on-disk location, my output is:
C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Shell\2.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Shell.dll
If it's under "C:\Windows\assembly\" you know it's in the GAC.
You can also do this without an Assembly.Load call if you already referencing the assembly you can enumerate the assemblies loaded into the current app.domain and just print out (or render to a literal control, or Response.Write, etc...) what their .Location properties are.
Edit: The code for that looks something like this:
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(a.GetName().FullName);
Console.WriteLine(a.Location);
Console.WriteLine();
}
Edit: On a full trust environment, the following code (console app) will enumerate the GAC and write out each assembly, it should be easy to modify it into an ASP.NET app, but I'm not sure if it will work in an environment that is less than full trust (just guessing here, you might get lucky):
static void ProcessFile(string file)
{
try
{
Assembly a = Assembly.LoadFile(file);
Console.WriteLine(a.GetName().FullName);
}
catch { /* do nothing */ }
}
static void ProcessFolder(string folder)
{
foreach (string file in Directory.GetFiles(folder))
{
ProcessFile(file);
}
foreach (string subFolder in Directory.GetDirectories(folder))
{
ProcessFolder(subFolder);
}
}
static void Main(string[] args)
{
ProcessFolder(@"C:\Windows\Assembly");
}