tags:

views:

484

answers:

4

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 used in project - this particular DLL is not present in BIN folder. And application is working fine on the server - but on my machine, obviously compiler is giving error. Ex-Developer insists that it is not in GAC on the server and 'it is what it is'. Now I need to check whether this DLL is registered in GAC or not.

Help will be appreciated.

Good Day;

+1  A: 

Check this codeproject GAC API Interface article. This uses undocumented fusion.dll to enumurate the GAC. But author claims that

This code is known to work with .NET 1.1 and 2.0. Please note that the DLL fusion.dll is different in 1.1 and 2.0. So if you have both frameworks installed, make sure to point the code to the right DLL. Otherwise most API-calls will fail. The default implementation uses the one found in the WINDOWS directory.

Cheers

Ramesh Vel

Ramesh Vel
thanks - will check; but I am afraid it might create an issue with permissions; as I have limited access to the server - and I doubt its functionality under ASP NET User.but thanks anyway; I saw it earlier too, but ruled out coz of above doubt. But lemme give it a try.
effkay
+1  A: 

You don't really need to write something in C# to find out if this specific dll is in the gac. You can use gacutil.exe with the /l option from the command line to list the contents of the GAC.

Mike Two
wish I could - I have limited access to server - i.e., FTP only :)but still, thanks for the comment
effkay
@effkay - sorry it wasn't helpful. If you have limited access to the server then how will a code solution help?
Mike Two
+2  A: 

If you have limited access to the server then this might work:

// List of all the different types of GAC folders for both 32bit and 64bit
// environments.
List<string> gacFolders = new List<string>() { 
    "GAC", "GAC_32", "GAC_64", "GAC_MSIL", 
    "NativeImages_v2.0.50727_32", 
    "NativeImages_v2.0.50727_64" 
};

foreach (string folder in gacFolders)
{
    string path = Path.Combine(@"c:\windows\assembly", folder);
    if(Directory.Exists(path))
    {
        Response.Write("<hr/>" + folder + "<hr/>");

        string[] assemblyFolders = Directory.GetDirectories(path);
        foreach (string assemblyFolder in assemblyFolders)
        {
            Response.Write(assemblyFolder + "<br/>");
        }
    }
}

It basically enumerates the raw GAC folders. It works on DiscountASP shared hosting so might work for your hosting environment.

It could be embellished by enumerating deeper into each assembly's folder to yank out the version number and public key token.

Kev
A: 

Hi effkay,

May be you need GAC viewer something like this:

alt text

Video: How to use Add GAC References Dialog

Hope this helps

Muse VSExtensions