Click here to Skip to main content
Licence 
First Posted 11 Apr 2006
Views 41,639
Bookmarked 14 times

How to use a DLL from the GAC

By | 11 Apr 2006 | Article
This article descibes how to use the methods in a DLL which is located in the Global Assembly Cache.

Introduction

This article describes how to use DLLs which are in the GAC. The technique described is very useful to use common projects in a secure way.

Background (steps to put a DLL in GAC)

First, in the command prompt, go to the folder in which the project DLL is saved. Then, create a strong name for that DLL by using the command sn -k [strong name.snk]. Then, put that strong name in the [assembly: AssemblyKeyFile("strongnamepath")] line in assemblinfo.cs, and build that project. Again in command prompt, type gacutil /i [assemblyname]. Now, the DLL is moved to GAC. In the code available for download, you will find out how to use the GAC DLL.

Using the code

You need to move the correct DLL to the GAC by following the above steps. In our example, PutitinGAC is the DLL to be moved to GAC.

The first step to do to refer a DLL in GAC is to assign it to the local assembly object fromGAC. While loading, the DLL version number and public key token should match that of the DLL in the GAC (c:\Winnt\assembly). In the DLL's properties, you can find the public key and version details.

Assembly fromGAC = Assembly.Load("PutitinGAC, " + 
     "Version=1.0.2292.30259, Culture=neutral," + 
     " PublicKeyToken=31f5625abd53197f");
Object[] oParam= {1,2};
Console.WriteLine(fromGAC.GetType(
   "PutitinGAC.Class1").GetMethod("add").Invoke(fromGAC,oParam));

Points of Interest

I am excited to know more about assemblies and the features they provide. It'd be great if anybody can update this with more functionalities.

History

  • Source code released: April 12 - version 1.0.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

thiaguramani

Web Developer

India India

Member

Having 1+ years of experience in dot net and web development

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionRe:Add reference to a dll in GAC [modified] Pinmembermail.roop@gmail.com16:39 3 May '12  
GeneralMy vote of 2 Pinmemberkribo3:44 3 May '11  
GeneralMy vote of 1 Pinmembermapfel21:29 20 Jan '09  
QuestionHow to use dll present in gac without adding refrence Pinmemberdeepak_bha19:06 31 Jul '08  
AnswerRe: How to use dll present in gac without adding refrence Pinmemberkribo3:21 3 May '11  
QuestionHow to upgrade an Assembly in GAC? PinmembertankSanju22:28 9 Aug '07  
Generalbut Main thing is how to USE our DLL which stored in GAC Pinmembernitinsuvagia22:21 8 Aug '07  
GeneralRe: but Main thing is how to USE our DLL which stored in GAC [modified] Pinmemberkribo3:12 3 May '11  
QuestionHow can I generate VB.NET codes? Pinmemberepala16:46 4 Dec '06  
GeneralMSI Installers PinmemberScott Hanslip6:30 12 Apr '06  
GeneralRe: MSI Installers Pinmemberthiaguramani19:53 24 Apr '06  
GeneralAssemblies Pinmemberkolbis19:36 11 Apr '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 11 Apr 2006
Article Copyright 2006 by thiaguramani
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid