TUTORIAL

How to give strong name to DLL and how to install DLL in GAC

Posted by Hemant Patil Tutorials | Windows Forms C# November 27, 2007
Tags: dll, GAC, strong name
This article tells you how to create strong name for your DLL files and also to install DLL in GAC.
Reader Level:

Steps for Giving  strong name to DLL

  1. Open .net command prompt.
  2. Go to the folder contanig DLL.
  3. Type sn -k test.snk, you can use any file name instead of test. This will create  test .snk file in that folder.
  4. Open the assemblyinfo.cs file of project.
  5. Type file path  in this tag [assembly:AssemblyKeyFile@"E:\hemant\practice\HP\bin\Debug\HP.snk")]
  6. Build  application, finally your strong name created for your DLL.

Example

  • Created class library path E:\hemant\practice\HP
  • Open command prompt go to Dll folder path.



  • Type sn -k HP.snk



This create  HP.snk file in E:\hemant\practice\HP\bin\Debug folder.

  • Open the  AssemblyInfo.cs file of project. 

    Type  path  of snk file in following attribue.



  • Build class library.              

Steps for  Installing  in GAC

  • After giving strong name in .net command prompt type gacutil in DLL path



this will install file in assembly.

  • Copy the DLL file C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 folder.



  • You can add references  to another  project  using .net tab.


  

Login to add your contents and source code to this article
post comment
     

When i tried to install dll in GAC i got some problem , plz help me. The error message is" Failure adding assembly to cache: The system cannot find file specified."

Posted by Gajanan Awakale Nov 24, 2011

You can add references to another project using .net tab. Note: in last fig shows our dll file installed into GAC. but mine installed , but in that tab that file is not showing as like last fig

Posted by Sutha Raghavan Sep 08, 2011

HI Hemant, I tried with steps you mentioned above, I got a warning "Use command line option '/keyfile' or appropriate project settings instead of 'AssemblyKeyFile' d:\Creations\MyAPP\MyApp\MyApp\Properties\AssemblyInfo.cs" I completed all steps but my dll is not found in "C:\Windows\Assembly". Please help me on this issue. Thanks. Amit.

Posted by Amit Pandey Feb 17, 2011

// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]

Posted by Anders Hundborg Jan 22, 2011

What if the dll I copy there isn't the same I registered on the GAC? Wouldn't that be a mess? Thanks

Posted by Jose Dec 26, 2008
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter