[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 989
  • Last Modified:

GAC Issues

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
daveamour
Asked:
daveamour
  • 2
  • 2
1 Solution
 
naveenkohliCommented:
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
 
daveamourAuthor Commented:
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
 
naveenkohliCommented:
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
 
daveamourAuthor Commented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now