Question How to use methods from another assemblies?

awesomeliar

New member
Joined
Oct 5, 2021
Messages
3
Programming Experience
Beginner
Im new to Csharp, and I read that with public classes, you can use methods of that class in another assembly. Im using Visual Studio 2019. I added a strong name key in properties in two assemblies, and I wrote gacutil.exe -i ConsoleApp1.dll (and ConsoleApp2.dll) in Visual Studio Commando Prompt, then I quit the Command Prompt - to add 2 assemblies to Global assembly cache. When I tried to make an instance of a class that is written in ConsoleApp1 in another assembly - in ConsoleApp2, it couldnt find that class.
 
How did you reference the other assembly?
 
ConsoleApp1.classname example =
new ConsoleApp1.classname(); doesn't work. This code worked however once I referenced only 1 assembly to the other through settings without Global Assembly cache.
 
That doesn't make sense. The GAC is not an alternative to referencing an assembly. The GAC is just a place that you can install an assembly so that all applications can access that one copy and it can be updated easily. You still have to reference an assembly if you want to use the types it contains, even if it's installed in the GAC. You seem to be under the impression that every application can just automatically use any assembly installed in the GAC. That's not the case.
 
So what does it mean that all applications can access a GAC assembly, if not that they can use it's methods automatically?
 
It means that each application doesn't have to include its own copy of the assembly when it's installed. If there's no GAC then either every application would have to store its own copy of the assembly in its own folder, leading to multiple copies of the same assembly, or you'd have to support each individual user having their own common library folder that could be anywhere on their machine.
 
Back
Top Bottom