Why do I need to reference this assembly, even if it is not used

I have an architecture like:

Data (a class library that processes our Entity Framework stuff)
Components (mid-level class library that references a data library)
WebOffice (a web application that references a component library but not a data library)

Now I have the following code snippet (it lives inside our Components.Payment.cs; tblPayment is contained in our data library.):

public static Payment Retrieve(int id) { var t = repository.Retrieve(id); //the above line returns a tblPayment object if (t != null) return new Payment(t); return null; } public static Payment Retrieve(tblPayment tblPayment) { return new Payment(tblPayment); } 

After that I added; WebOffice project gives the following error:
errorCS0012: The type "Data.Model.tblPayment" is defined in an assembly that is not referenced. You must add a reference to the assembly 'Data, Version = 3.5.0.0, Culture = neutral, PublicKeyToken = 749b8697f3214861'.

Now this makes no sense to me, because the WebOffice project doesn't call the Retrieve (tblPayment tblPayment) method at all. (This is used only in the Components library)

Any clue why it will request a link to the data? Do I need to reference each library that the library link refers to? (try saying 5 times fast ...)

+6
reference c # assemblies
source share
3 answers

The general rule is that a link to the containing assembly of any type in the public interface of another assembly must be added to the project. Otherwise, the compiler does not know how to enable this type.

To answer the second question, you do not need to add links to assemblies that contain types only used internally for other assemblies.

+6
source share

The compiler must know that tblPayment to perform overload resolution using the Resolve method.

+2
source share

You cannot allow a public interface for a library without parameter information for all of its functions. If you are referencing a library in which a public method of an open type accepts a parameter of type X, you need to know what X is, whether you use this method or not.

+1
source share

All Articles