Denis
Denis

Reputation: 3757

Hierarchical dependency and "The type is defined in an assembly that is not referenced"

For example, I have three class libraries: L1, L2 and L3. L1 has type T1. L2 has type T2. L2 has reference to L1. L3 has reference to L2. L3 has NO explicit reference to L1.

It compiles and works absolutely okay if T2 class looks like:

public class T2
{
    T1 GetT1() { ... };
}

But if T2 uses T1 as parameter in constructor, it says T1 is defined in an assembly that is not referenced. when I build L3:

public class T2
{
    T2(T1 t1) { ... };
    T1 GetT1() { ... };
}

Is it possible somehow to ignore this error? I do not use constructor with T1 in L3 and do not want to add reference to L1.

Upvotes: 0

Views: 32

Answers (1)

Michael Palermo
Michael Palermo

Reputation: 306

When you expose the type in constructor it mandates a reference to type library. This is a classic example of when to use either an interface or abstract class.

Upvotes: 1

Related Questions