Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project reference not working in VisualStudio2010

I've got a Solution with lots of projects and all but one of them is behaving. The one that is not working is a ConsoleApplication, and it relies on C# Class Library project. I've added a reference to the library project, and add the namespace (which I've checked is correct), but everywhere I reference the classes in my library, I get:

The type or namespace 'MyClass' could not be found (are you missing a using directive or an assembly reference?).

The library project is building successfully (I can see the DLLs appear in the bin folder) and I've tried a project reference, and also a reference to the DLL itself. Neither works.

Also, all projects are set to build with a platform target of 'Any CPU'.

I've tried pretty much every suggestion I've come across on forums with no success. Can anyone shed some light on what's going wrong?

Thanks

This solved the problem:

The console application had a Target framework of .NET Framework 4 Client Profile, whereas the library just had .NET Framework 4. I set the console app to .NET Framework 4 and it all builds perfectly.

like image 587
Richard Avatar asked Mar 20 '12 15:03

Richard


People also ask

How do I add a project reference in Csproj?

You can also right-click the project node and select Add > Project Reference. If you see a References node in Solution Explorer, you can use the right-click context menu to choose Add Reference. Or, right-click the project node and select Add > Reference.

How do you add references to a project?

Add a reference In Solution Explorer, right-click on the References or Dependencies node and choose either Add Project Reference, Add Shared Project Reference, or Add COM Reference. (You can right-click the project node and select Add from the fly-out menu to choose from these options, too.)


2 Answers

My bet is on a framework mismatch between your library and you app... Check if your library is not building with a superior version than you app, or if your app is building with a Client profile flavor

like image 113
Cédric Rup Avatar answered Sep 28 '22 14:09

Cédric Rup


It is probably that one of your DLLs references some part of the .net framework that is not referenced in your console application. For example if one of your class library projects has asp.net server controls in and references System.Web, but your console application does not reference System.Web it will not build and you will get that error. But it is not obvious because the DLLs referenced are stored in the GAC so they would never appear in your bin folder.

like image 36
Ben Robinson Avatar answered Sep 28 '22 14:09

Ben Robinson