Reputation: 1993
To maintain the separation of concern, I am trying to create the layered project architecture. lets consider below example.
ProjectA
is class library
and has
IntefaceA
ClassA
implements InterfaceA
ProjectB
is class library
and reference ProjectA
and has
ClassB
inherit ClassA
( PrjectA reference added in ProjectB )ProjectC
has
ClassC
which inherited from ClassB
so added ProjectB
as reference in ProjectC
Now issue is, in ProjectC
I am getting error The type ClassA is defined in an assembly that is not referenced
Questions is
ProjectC
need ProjectA
reference referenced project
all way to the hierarchical chain Upvotes: 0
Views: 103
Reputation: 107
This is a commonly complained about feature of the visual studio compiler. It will only build out and link assemblies that are referenced directly in the project, it doesn't iterate through the hierarchy.
If ClassC has a direct dependency on code in Project A, it needs to reference ProjectA to compile correctly.
You don't need to include the entire hierarchy in every project, just what it references. If Project B references Project X, Y, and Z for other things, but Project C doesn't derived from anything from Project B that uses them, then Project C doesn't need a reference.
One way to keep things separate and reduce direct dependencies like this is to use dependency injection frameworks. MEF is such an example. https://learn.microsoft.com/en-us/dotnet/framework/mef/
In this case, where you are directly deriving from a class that directly derives from anther class in another assembly, you are basically stuck referencing that assembly, since the compiler requires it to properly compile your ClassC, and isn't designed to iterate through the dependency hierarchy.
Upvotes: 1