ASP.NET - GAC - Asked By Naresh Kumar on 02-Aug-11 10:15 AM

Hi All,

I have taken a sample class library and generated SNK, and added the below line in AssemblyInfo.cs file.

[assembly: AssemblyKeyFile(@"Path\bin\Debug\TestingLib.snk")]
After building the Project I have installed the DLL into GAC using the below command
gacutil -I path\Test.dll

It has been successfully installed and able to see the DLL in the folder C:\\Windows\\Assembly\Test.dll .

Then I have taken the new web project and click on Add Reference I am not able to find the Test.dll in the .NET Tab.

Please advise.

Ravi S replied to Naresh Kumar on 02-Aug-11 10:23 AM

The global assembly cache (GAC) is a machine-wide code cache that stores assemblies specifically designated to be shared by several applications on the computer.

The Global Assembly Cache in the .NET framework provides a central place for registering assemblies. These assemblies once registered are then available to all applications for usage.

Global assembly cache is nothing but a special disk folder where all the shared assemblies will be kept. It is located under <drive>:\WinNT\Assembly folder.

Global Assembly Cache

To create a small Class Library project by using Visual Studio .NET or Visual Studio 2005, to generate a strong name, and to install the project's .dll file in the Global Assembly Cache, follow these steps: 
  1. Open Visual Studio .NET or Visual Studio 2005.

  1. Create a new Class Library project named GAC in Visual Basic .NET or in Visual Basic 2005.
  1. A strong name is needed. To generate this cryptographic key pair, use the SN Tool, which is located in the \bin subdirectory, where the .NET Framework Solution Developer Kit (SDK) is installed. The SN Tool is very easy to use. The command-line statement takes the following form:
    sn -k "C:\[DirectoryToPlaceKey]\[KeyName].snk"
  2. For convenience, create a directory named GACDemo in C:\ so that you can easily locate the key and access the key from the command prompt.

    NOTE: For most users, the .NET tools are located in C:\Program Files\Microsoft.NET\FrameworkSDK\Bin. Before you type the following SN command, you may want to copy this similar path on your computer to the .NET bin directory, type cdfrom the command prompt, right-click to paste the path, and then press ENTER to quickly change the directory where the SN Tool is located.

    Type the following:
    sn -k "C:\GACDemo\GACkey.snk"
    Note In the .NET Framework 2.0, the .NET tools are located in the C:\Program Files\Microsoft.NET\SDK\v2.0\Bin folder.
  3. A key is generated, but it is not yet associated with the project's assembly. To create this association, double-click the AssemblyInfo.vb file in the Visual Studio .NET or Visual Studio 2005 Solution Explorer. Add the following to the list of assembly attributes that are included in this file by default when a project is created in Visual Studio .NET or in Visual Studio 2005:
    <Assembly: AssemblyKeyFile("C:\GACDemo\GACKey.snk")>
    Compile the project by clicking CTRL+SHIFT+B. No further code is necessary at this point in order to install a .dll file in the GAC.
  4. You can install the .dll file by using the Gacutil Tool or by dragging the .dll file into the appropriate directory. If you use the Gacutil Tool, you can use the following command:
    gacutil -I "C:\[PathToBinDirectoryInVSProject]\gac.dll"
    If you want to drag the file, use Microsoft Windows Explorer. Open two instances of Windows Explorer. In one, navigate to the location of the .dll file output for your console project. In the other, navigate to c:\[SystemRoot]\Assembly.

Reena Jain replied to Naresh Kumar on 02-Aug-11 10:33 AM

When you are working in Visual Studio you have Solutions and Projects. You can only work on one solution at a time - but one solution can have many projects in it.
The way to add a project to a solution is
  • right-click on the "Solution" in the solution explorer and
  • select Add-> Existing Project
  • Select your project and it will be added to your solution.
In order for one project to see the classes and objects in the other then you must make a reference between the two.
One project can only reference the other though. Two projects can not reference each other because the compiler will not know which one to compile first.

hope this will help you
Radhika roy replied to Naresh Kumar on 02-Aug-11 11:22 AM

Based on my understanding, you want to add reference to an assembly from GAC by the following steps: Project->Add Reference->Browse tab->Locate the (GAC)assembly folder and select a reference and then click OK. But the assembly cannot be added to your application. If I have misunderstood you, please feel free to let me know.

As far as I know, we cannot add references from the Global Assembly Cache (GAC). But we can add references from .NET tab or to select a component in the file system in the Browse tab of the Add Reference Dialog Box. For more information, see