Thursday, September 11, 2008

How to add reference of a DLL/Assembly registered in Global Assembly Cache (GAC)

To add the reference of a DLL/Assembly in .Net project, usually we right-click the Solution in Solution Explorer and click the Add Reference menu.



After clicking the Add Reference menu, Add Reference pop-up dialog box gets open.



If the DLL/assembly is .Net based one, then we click .Net tab else we browse to the DLL/assembly by clicking the Browse tab.

Here the problem comes; if the DLL/assembly is GAC registered then we can’t directly browse to C:\Windows\Assembly and select the DLL/assembly.


For example, I registered a SampleWebParts DLL/assembly in GAC, so to access it first open the Command Prompt. Then go to following location using CD command:

C:\>cd WINDOWS\assembly\GAC_MSIL\SampleWebParts\1.0.0.0__992b220d2c0fa2a6



Note: SampleWebParts is my DLL name. SampleWebParts directory contains only one folder with name starting with 1.0.0. … .


Now if we check the directory contents with Dir command then we can see our required DLL.
So copy the above path and combine it with DLL name.
C:\WINDOWS\assembly\GAC_MSIL\SampleWebParts\1.0.0.0__992b220d2c0fa2a6\SampleWebParts.dll


Paste the above complete path in File Name area of Add Reference dialog box.



Press OK button to add the reference of a DLL/Assembly registered in Global Assembly Cache (GAC) in your desired solution.

3 comments:

Gautham said...

Nice explanation.. :)

Anonymous said...

this is what i was exactly looking for..

Many thanks
shtapi

LowProfile said...

When I add reference using path + dll I receive an alert: "The file name is not valid."

Any suggestion?

Thanks
Roger

Google