I've got an architecture like the following:
Data (Class Library that handles our Entity Framework stuff)
Components (Middle tier class library that references Data library)
WebOffice (Web Application that references Components library, but NOT Data library)
Now, I have the following snippet of code (this lives inside our Components.Payment.cs; and 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 I added this; the WebOffice project is giving the following error:
errorCS0012: The type 'Data.Model.tblPayment' is defined in an assembly that is not referenced. You must add a reference to assembly 'Data, Version=3.5.0.0, Culture=neutral, PublicKeyToken=749b8697f3214861'.
Now, this doesn't quite make sense to me, because the WebOffice project isn't calling the Retrieve(tblPayment tblPayment) method at all. (That's only being used inside the Components library)
Any clue why it would be asking for the Data reference? Do I need to reference every library that a referenced library references? (try saying that 5 times fast...)
The general rule here is that a reference 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 resolve that type.
To answer your second question, you do not need to add references to assemblies that contain types which are only used internally to other assemblies.
The compiler needs to know what tblPayment
is in order to perform overload resolution on the Resolve
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With