Using Global Assembly Cache (GAC) - So that it is designed for

Is the following solution the only way to use libraries from the GAC in code?

Assembly lib = Assembly.Load("MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31f5625abd53197f"); Console.WriteLine(lib.GetType("MyClass").GetMethod("Start").Invoke(obj, null)); 

I am a little confused - I read a lot about the GAC, and I know how to sign the assembly, assembly and uninstallation of the assembly in the GAC, but I don’t know how to use it and how it helps programmers (except that it stores different versions of one and the same library). I wish that I could normally create classes, and not force the methods presented above to be called.

I do not need any work, such as: "modify the Windows registry", because I do not think that the GAC was intended for such manipulations. I want a simple answer: why do I need a GAC, does the runtime use it in some way?

What is the point of using the GAC when the code gets really ugly and hard to manage? Or maybe I'm missing something? Maybe I need to manually copy the assembly to my local folder? But I heard that this is also difficult to do.

+1
source share
3 answers

GAC Component Helps You Have Multiple Versions (that is a public key to prevent name conflicts) of assemblies installed side by side and available for the whole machine, not just your application directory.

So, accessing assemblies from the GAC using the version number is pretty much the same as how the GAC was designed .; -)

btw: you should not dynamically upload files when you do not need it.

IOW: If you already know the class name and version of the assembly, you can simply reference this assembly and skip a rather sharp decrease in performance, not only loading the assembly dynamically, but also invoking methods by reflection. (Instead of reusing them through interfaces or delegates)

+4
source

If your assembly was ngen'ed or GAC'd, then the application will use this automatically if all (hashes, etc.) match.

+1
source

If you reference the assembly in your project, you can use it as a normally referencing DLL that is not in the GAC.

0
source

Source: https://habr.com/ru/post/899619/


All Articles