?
Solved

GAC Issues

Posted on 2002-07-28
4
Medium Priority
?
987 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 200 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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