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.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,762
Location
Chesapeake, VA
Programming Experience
10+
How did you reference the other assembly?
 

awesomeliar

New member
Joined
Oct 5, 2021
Messages
3
Programming Experience
Beginner
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.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,130
Location
Sydney, Australia
Programming Experience
10+
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.
 

awesomeliar

New member
Joined
Oct 5, 2021
Messages
3
Programming Experience
Beginner
So what does it mean that all applications can access a GAC assembly, if not that they can use it's methods automatically?
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
4,130
Location
Sydney, Australia
Programming Experience
10+
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.
 
Top Bottom