Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I reference my class library?

I have a solution that contains a website and a class library in Visual Studio 2008.

I then have another web site project outside of the solution that needs to reference the class library. I right click the Bin folder or Project and select Add Reference, then select my Class Library Project, it adds the 15 or so DLLs that the class library needs to the websites bin folder, but none of the .cs files recognize the using statements.

using MyLibrary.MyFolder; 

It says that it can't resolve it, and ReSharper just says it can be safely removed since it's not being used.

ReSharper can recognize that it needs the reference and suggests that it "Reference MyLibrary and use MyFolder". I'm not sure why it's suggesting I add a reference I already have. When I go with the suggestion, I get the error

"Failed to reference module. Probably, reference will produce circular dependencies between projects."

I've tried going to the websites property pages and removing all the references and re-adding them, but it gives the same errors. Any ideas why this isn't working?

like image 459
Brandon Avatar asked Feb 09 '10 19:02

Brandon


People also ask

How do you reference a class library?

On the Menu bar, you would click Project -> Add Reference or In the Solution Explorer, you would right-click References and click Add Reference. You can click the Browse tab, locate the folder where the library resides and select it.

How do I resolve a reference problem in Visual Studio?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.


2 Answers

Also, check that the new solution's projects run against a compatible framework to the project you're trying to include. I was trying to include a reference to a 4.0 project in a 3.5 project.

like image 200
CindyH Avatar answered Sep 28 '22 23:09

CindyH


I found how to fix this issue (for me at least). Why it worked, I'm not sure, but it did. (I just tried against a second website that was having the same problem and the following solution worked for that as well).

I tried the normal cleaning of the projects and rebuilding, shutting down all my Visual Studio instances and restarting them, even tried restarting my computer.

What actually worked was opening up the project in Visual Studio, closing all the open tabs, and then shutting it down.

Before I had left the tabs open because I didn't think it mattered (and I hardly ever close the tabs I'm using).

like image 26
Brandon Avatar answered Sep 28 '22 23:09

Brandon