Friday, September 19, 2008

Register / Unregister a DLL file with GAC (Global Assembly Cache)

In order to use a DLL (Dynamic Link Library) in your C# .NET code, you need to register the DLL file with the Global Assembly Cache (GAC). Since I am new to .NET and I do not know much about GAC myself, to me GAC is just a folder containing all your DLLs. If the desired DLL file is not in GAC folder, you cannot use it in your .NET code, in my case, C# .NET code.

Location of GAC: C:/Windows/Assembly <-- This is your GAC Folder

You cannot "Drag & Drop" or "Copy Paste" your desired DLL file in the GAC folder. Atleast it didn't work in my case. You need to "register" or "install" your desired DLL file using a utility named "gacutil"

So, for example, you have a DLL file named "mylib.dll", this is how you would register your DLL file with GAC using "gacutil".

1- Open up Command Prompt or type "cmd" in the Run Dialog box, windows Command Prompt
will pop-up
2- Type in this command to register or install the DLL file "mylib.dll"
gacutil /i c:\myfiles\mylib.dll
3- Now go to the GAC folder (c:\windows\assembly) and look for the DLL file you registered using using the command in Step 2. The DLL file should now appear in the GAC folder.
4- You are ready to reference your new installed DLL file in your C# Code via "using" keyword.
5- To uninstall any DLL file you need to run the following command
gacutil /u c:\myfiles\mylib.dll
6- Switch "/i" in the command stands for "INSTALL" and switch "/u" in command stands "UNINSTALL", obviously.

Hope this helps!

Flare Kit Headline Animator