Click here to Skip to main content
Click here to Skip to main content

How to use a DLL from the GAC

By , 11 Apr 2006
 

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionRe:Add reference to a dll in GAC [modified]membermail.roop@gmail.com3 May '12 - 16:39 
GeneralMy vote of 2memberkribo3 May '11 - 3:44 
GeneralMy vote of 1membermapfel20 Jan '09 - 21:29 
QuestionHow to use dll present in gac without adding refrencememberdeepak_bha31 Jul '08 - 19:06 
AnswerRe: How to use dll present in gac without adding refrencememberkribo3 May '11 - 3:21 
Hi,
 
Not quite shore what your request is.
You've got 30 [*.dll] files stored in your GAC and wish to acces them threw a single peace of code..
I suggest you write yourself a global [*.dll] that mainly works as an Interface.
And everytime you create a new [*.dll] you add it to the Global.
 
Once made a Global just delegate your Interfaces
 
Hope this was helpfull or at least a valid suggestion.
Grtz
Kribo

QuestionHow to upgrade an Assembly in GAC?membertankSanju9 Aug '07 - 22:28 
Generalbut Main thing is how to USE our DLL which stored in GACmembernitinsuvagia8 Aug '07 - 22:21 
GeneralRe: but Main thing is how to USE our DLL which stored in GAC [modified]memberkribo3 May '11 - 3:12 
QuestionHow can I generate VB.NET codes?memberepala4 Dec '06 - 16:46 
GeneralMSI InstallersmemberScott Hanslip12 Apr '06 - 6:30 

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

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