1

I follow the main instructions on adding my Library Class to the Global Assembly.

1 - Create a strong name key pair (/ArchieDLLTesting/bin/Debug/ArchieDLLTesting.snk)
2 - Sign the assembly via Visual Studio (Project property, Sign, Browse that file and Save)
3 - Installing into the GAC (gacutil –I /ArchieDLLTesting/bin/Debug/ArchieDLLTesting.dll)

This is the code of the Library (for a unique/single class I have):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArchieDLLTesting
{
    public class ArchieSayHello
    {
        public ArchieSayHello()
        {
        }

        public string SayHello()
        {
            return "Hello Archimedo";
        }
    }
}

All operation got successfull! Now, if I open an empty project, and I type for example:

using ArchieDLLTesting;

it does not find that assembly. I've checked the Windows/assembly/GAC_MSIL folder and there isn't my DLL.

So what's wrong here?

markzzz
  • 47,390
  • 120
  • 299
  • 507
  • win xp or higher version ?? – Thilina H Oct 02 '13 at 10:18
  • I stated this already in my first comment in your previous question [here](http://stackoverflow.com/questions/19132552/can-i-share-a-mine-library-to-all-applications#comment28295114_19132552) – Sriram Sakthivel Oct 02 '13 at 10:19
  • Windows 7 Professional. System is 64bit, VS should be 32, but that I'm not so sure :) – markzzz Oct 02 '13 at 10:20
  • 1
    *if I open an empty project, and I type for example: using ArchieDLLTesting; it does not find that assembly* That's not how the GAC works. – ta.speot.is Oct 02 '13 at 10:25
  • Also, putting an assembly in the GAC should be a largely academic endeavour. http://msdn.microsoft.com/en-us/library/yf1d93sz.aspx *You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required* – ta.speot.is Oct 02 '13 at 10:35

3 Answers3

3

Of course you still need to add a reference to the DLL. Just inserting a using statement does not use the DLL from the GAC.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • Uhm, so what I have to do? – markzzz Oct 02 '13 at 10:18
  • Right click "References" in your project, then "Add reference" and then select your DLL. – Thorsten Dittmar Oct 02 '13 at 10:20
  • @giammin Explain *this is not true* ? – Sriram Sakthivel Oct 02 '13 at 10:21
  • Uhm? Such as every kind of reference? So why use Global Assembly when I can just add that reference? – markzzz Oct 02 '13 at 10:22
  • @SriramSakthivel forget it! you need to add it to the project reference – giammin Oct 02 '13 at 10:23
  • 1
    @markzzz Adding a DLL to the GAC only frees you from having to deploy the DLL along with your application if it is shared among many applications. You still need to reference the assembly! You can't even reference it directly from the GAC! You need to reference the original file. The only difference is, it won't be copied to your project, the system fill find it through the GAC. – Thorsten Dittmar Oct 02 '13 at 10:24
  • @markzzz That's why most people I know simply don't use the GAC at all, but simply reference the original DLL and deploy it along with the application. – Thorsten Dittmar Oct 02 '13 at 10:26
2

Seems your machine is win 7 then your dll in C:\Windows\Microsoft.NET\assembly\GAC_64 or C:\Windows\Microsoft.NET\assembly\GAC_32.its depend on you bit version. Just check those folders. Any way within your project definitely you should add as project reference that dll. When the running time framework took reference from GAC’s dll.

UPDATED:

But if you keep updating that GAC dll project[ArchieDLLTesting], keep it mind to GAC again. Otherwise running time your application reference old version of that assembly. In that case you can add build event to GAC automatically on that particular project using following post built event.

"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\gacutil.exe" /i "$(TargetPath)"
Thilina H
  • 5,754
  • 6
  • 26
  • 56
  • This is interessant, also because I just opened this http://stackoverflow.com/questions/19135004/gac-on-edit-process?noredirect=1#comment28298999_19135004 . But, how can I use this post built automation event? -i (or just /i) it the standard command. Are you saying that after a Build windows can automatically do the gac to the repository? Or am I wrong understand? – markzzz Oct 02 '13 at 10:57
  • 1
    Yes, Under Build Event in project properties you can add post build event to GAC.but make sure that exe in that path 'ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\gacutil.exe' – Thilina H Oct 02 '13 at 11:03
2

I think you have confused what GAC means:

Global Assembly Cache is a central repository where you can store the assemblies that many application needs.

If you put an assembly in the GAC than you can reference it witouth needing the physical assembly in the bin directory

Think about Framework assembly

You don't need to copylocal them when you reference it.

So the solution is to add that reference to your project

Anyway it is not a good practice to put assembly in the GAC

There are very few situation when you should put them there:

When should I deploy my assemblies into the GAC?

Community
  • 1
  • 1
giammin
  • 18,620
  • 8
  • 71
  • 89
  • But I need it! A central source where I put the DLL that every of my Project needs. So if I edit the DLL, I edit it for ALL projects, and I don't need copy & paste to each application. This is a good way I believe? – markzzz Oct 02 '13 at 10:39
  • @markzzz no it is not! it is a long story to tell but you can read it there http://stackoverflow.com/questions/2451123/when-should-i-deploy-my-assemblies-into-the-gac – giammin Oct 02 '13 at 10:42
  • I read most of them! So for my scenario what should I do? DLL along each application is terrible... what do you suggest? – markzzz Oct 02 '13 at 10:43
  • @markzzz why it is terrible??? it is what they are meant for. any app should be a sandbox. maynly if they don't need to talk togheter – giammin Oct 02 '13 at 10:44
  • "any app should be a sandbox?" Not imo :) Imagine I have 200 website, and at some point I want to upgrade a function inside the DLL. I need to copy&paste all DLL for each project... I don't want this! I don't see any problem on using a shared repository like GAC here... – markzzz Oct 02 '13 at 10:46
  • imagine if you need to upgrade a gac dll only for one site because in that site you need to upgrade and the others will not work with the new dll – giammin Oct 02 '13 at 10:47
  • i also have many sites that use my "framework" dlls. I use nuget to handle references and nant, msbuild script to deploy them. I know it could be easy to put them in the gac. But i know that at some point the chickens are coming home to roost – giammin Oct 02 '13 at 10:49
  • It is not my scenario :) Every functions are the same for ALL application, and I never remove function, only add (or correct the wrong one). In fact my DLL its a sort of propretary CMS Data Layer. – markzzz Oct 02 '13 at 10:51
  • @markzzz in this case IMHO you should have only 1 website/ application which display 200 sites and not 200 sites – giammin Oct 02 '13 at 10:53