Solved

GAC Issues

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

I follows this article:

http://www.aspzone.com/articles/john/GAC/

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 Studio.net it gives the following error:

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

and

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?

Cheers

Dave
0
Comment
Question by:daveamour
[X]
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
4 Comments
 
LVL 23

Accepted Solution

by:
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("1.0.0.0")]

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.

Naveen
0
 
LVL 19

Author Comment

by:daveamour
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?

Thanks

Dave
0
 
LVL 23

Expert Comment

by:naveenkohli
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();
ob.foo();

0
 
LVL 19

Author Comment

by:daveamour
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

Dave
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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