Two libraries referencing the same DLL

125 views Asked by At

Say I have two class libraries in C# and an outside project that I want to use those libraries in:

LibA.dll
LibB.dll which also references LibA.dll because it uses some of its classes.
Project C which references both LibA.dll and LibB.dll

Lets say inside of LibB.dll I have a method that returns a class type from LibA.dll and inside of my project, I want to immediately set the proper class types when calling that method. For example:

LibA.classInsideLibA myObj = LibB.getClassInsideLibAInstance();

This should work, but I am wondering if there will be any issues present when referencing LibA.dll and LibB.dll inside of my project when LibB.dll already references LibA.dll. Does referencing LibB.dll automatically reference LibA.dll in this case?

2

There are 2 answers

4
MikeH On BEST ANSWER

You already do this all the time. Take for instance the string class and pretend that's your LibA. I'm sure you've got a library that returns a string. You've also probably returned a string from your library and referenced mscorlib (where String lives) in your main project.

This is no different.

System.String myString = LibB.GetSomeString();
0
pm100 On

". Does referencing LibB.dll automatically reference LibA.dll in this case"

I assume we are discussing refernces in VS projects . Of course all dlls have to be available at runtime

It depends. If you have projX->DLLA->DLLB

if DLLA uses DLLB but doesnt expose any of DLLB types (ie returns a DLLB class in one of its methods) then ProjA doesnt need to know about DLLB

If DLLA does return DLLB classes the projA needs a reference to DLLA and DLLB