MSDN Archive Home
Help and FAQs
Register Assembly in GAC
All Resource Updates
Change History (all pages)
The process to register Assembly in GAC (Global assembly Cache)
To share assemblies within an ASP.NET web application they are required to be placed within the \bin directory, but in order to share them through different applications existing on the same web server it is required to install them into the Global Assembly Cache (GAC).
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, including the development environments like Visual Studio.NET and Web Matrix etc.
Process of register Assembly into GAC
It involved many steps, which are as follows.
Creating a strong Name
After creating an assembly and before registering it to the Global Assembly Cache the first thing that is required is to assign a strong name to the assembly. What is a strong name? Well! a strong name is basically assigned to an assembly or a component to distinguish it from other assemblies and components existing in the GAC. A strong name consists of an assembly identity (name, version, etc.), public key and a digital signature.
Assigning a strong name to an assembly ensures that it would have uniqueness, version protection and code integrity. Assigning a strong name to an assembly is not a difficult task. A utility known as the sn utility, can be used to generate strong names, which are then added to the code of the assembly. For example, to create a strong name for an assembly named as sample.dll, you would write on the command prompt.
sn -k sample.snk
This would generate a strong name key pair and store it in a file named as sample.snk. The extension of the file can be anything, but mostly .snk is used as a convention. The -k option here is for creating a strong name key pair.
Associating a Strong Name with the Assembly
After generating the strong name key pair file, it is required to associate this file with our assembly, for doing that you have to add the following lines in the code of your assembly.
Note here that the information regarding the file containing the strong name key pair is placed in the code file before the namespace/class declaration. Also you are required to import the
namespace in order for the statement to work, otherwise the compiler would be showing you an error stating that it does not recognize the <assembly: AssemblyKeyFile("sample.snk")> statement.
Adding Assembly in the GAC
After compiling the assembly with the statements, containing the strong name information being added to it, you now have to place the assembly into the GAC.
Assemblies are located at: “
You can use a utility gacutil that is installed with the .NET framework. For adding an assembly you would write as follows on the command prompt.
gacutil /i sample.dll
Here the /i option is for installation. And for removing an assembly from the GAC, you can use the same utility as follows.
gacutil /u sample.dll
The /u option here is for uninstalling or removing an assembly from the cache.
Add reference in your project
(1) For adding reference of a
in .Net project usually we right-click the Solution in
and click the
(2) After clicking the Add Reference menu,
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.
(3) Here the problem comes; if the DLL/assembly is
registered then we can’t directly browse to
and select the DLL/assembly.
For example, I registered a
DLL/assembly in GAC, so to access it first open the
. Then go to following location using
is my DLL name.
directory contains only one folder with name starting with *1.0.0. … *.Means after assembly folder you have to right manually GAC
(double Underscore)<Public Key Token>
Now if we check the directory contents with
command then we can see our required DLL.
(4) So copy the above path and combine it with DLL name.
Paste the above complete path in
button to add the reference of a DLL/Assembly registered in Global Assembly Cache (GAC) in your desired solution.
Mar 28 2011 at 9:16 AM
, version 3
Sign in to add a comment
There is no current default release for this Resource Page.
More Tags ...
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.