I have an ASP.Net project (ProjA) and a class library project (LibB). I created a custom class (ClassC) in the library and added references to an existing dll (DllD).
I chose the Add reference option in ProjA and from the Solution tab I selected LibB and added the reference.
In ProjA I created an instance of ClassC. To my surprise, it didn't compile and showed me an error: DllD must be added as a reference to my ProjA.
Here is the message:
The type 'XXXX' is defined in an assembly that is not referenced. You must add a reference to assembly 'YYYYYY, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxx'.
Well, XXX is a class that is the base of ClassC and the dll is referenced in the LibB project.
Then what's the point of LibB? I don't want to add DllD to my ProjA project, I just want to use a custom class that depends on it in another project.
Is it normal that I have to add dlls like that? What should I set to make my LibB contain the DllD dll?
The problem is,
LibB
must be exposing some of the types contained inDllD
to your code inProjA
.1If it just consumed those types behind the scenes, then the reference wouldn't be necessary. But that's not, apparently, what it does. So the compiler wants a reference to be able to fully understand the types and members in
LibB
.Based on your edit:
Yes, the compiler needs to understand the class, including all of it's base classes. If, instead of inheritance, you used composition, and
ClassC
just contained a private reference to anXXX
instance, the reference wouldn't be required.1The most obvious way would be: