views:

132

answers:

3

Hey everyone,

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...)

+2  A: 

The compiler needs to know what tblPayment is in order to perform overload resolution on the Resolve method.

SLaks
+1  A: 

You can't resolve the public interface for the library without information about the parameters to all of its functions. If you're referencing a library wherein a public method on a public type accepts a parameter of type X, you need to know what X is, regardless of whether you're currently using that method or not.

Mike Burton
+6  A: 

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.

Brian Gideon
Makes complete sense. I was able to flag the Retrieve(tblPayment tblPayment) method as being internal; and my problem went away. Thanks again!
Jim B