Solved

GAC Issues

Posted on 2002-07-28
4
980 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
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now