GAC Issues

Posted on 2002-07-28
Last Modified: 2008-03-06
I have some issues with adding a .net class to the GAC

I follows this article:

And it seemed to work fine.  To add the DLL to the GAC though I just dragged and dropped it in explorer.

My first problem is that my code compiles when I do so at the command line but from Visual it gives the following error:

C:\Documents and Settings\daveamour\My Documents\Visual Studio Projects\ClassLibrary1\Class1.cs(4): Duplicate 'AssemblyVersion' attribute


C:\Documents and Settings\daveamour\My Documents\Visual Studio Projects\ClassLibrary1\Class1.cs(5): Duplicate 'AssemblyKeyFile' attribute

Here is my class code:

using System;
using System.Reflection;

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyKeyFile("dotNETComponent.snk")]

public class Maths
     public Maths()


     public int AddNumbers (int a, int b)
               return a + b;

My other issue is once my class is in the GAC, how do I actually use it in my code?


Question by:daveamour
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 23

Accepted Solution

naveenkohli earned 50 total points
ID: 7185307
If you want to create a component that will live in GAC, then you will have to be careful with the versioning. You have specified AssemblyAttribute that is opn ended. you will need to speciy fixed version.

[assembly: AssemblyVersion("")]

There is a assembly.cs file in your VS.Net project. It already has AssemblyFile attribute. you can't specify this attribute twice for an assembly. Either remove that or remove the one you are using with class definition.

The reason it compiled fine from command line is because you did not include assembly.cs file in compilation. You can do the same from VS.Net IDE. right click on Assembly.cs file and click on "Excluse From Project".

Using your strongly named assembly from GAC is same as any other assembly. Only differnce is that you no longer has to copy this assembly in bin folder under your app. And you can implement versioning for your library and make the client application use particluar versions of it.

LVL 19

Author Comment

ID: 7186835
Ok thanks, thats a great help.

I must be being thick though as I don't know hwo to use this Class.

My Class is Maths as you can see from the above code but my project was saved as ClassLibrary1 in the GAC.

How do I use this - I've tried using ClassLibray1 but that doesnt work.  Can you give me an idiots guide please?


LVL 23

Expert Comment

ID: 7186931
put you class under a namespace.

namespace davLibs
 public class Maths

Compile it. And then inthe project where you want to use it, add reference to this library and at the top of file import your namespace (although not ncessary).

using davLib;

Maths ob = new Maths();;

LVL 19

Author Comment

ID: 7192619
Ok thanks, I still have some issues but I've managed to get something working.   I'll go and do some more work then maybe come back with a fresh question.

Many thanks


Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where does legacy ASP.NET initialize language? 2 100
IDE for Python 5 104
Problem to Office 1 66
How do I "share" on social sites? 2 37
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question