113

I have a C# solution with two projects: a service (the main project) and a logger. The service uses classes from the logger. I've added a Reference to the logger project within the service project. At design time, autocomplete works fine: the logger's classes are visible, references that I use are colored appropriately.

I Rebuild the solution, and things go wrong. The references are no longer recognized: "The name 'Logging' does not exist in the current context' and the classes no longer exist in autocomplete. Removing and reattaching the reference gets me back to the base state of having the identifiers visible to autocomplete.

I've rebooted, cleared all caches, made sure this is the only instance of VS 2010 running on my machine.

Is there something obvious (obviously) that I'm missing?

Vikrant
  • 4,920
  • 17
  • 48
  • 72
Bob Kaufman
  • 12,864
  • 16
  • 78
  • 107

2 Answers2

165

Check your build types of each project under project properties - I bet one or the other will be set to build against .NET XX - Client Profile.

With inconsistent versions, specifically with one being Client Profile and the other not, then it works at design time but fails at compile time. A real gotcha.

There is something funny going on in Visual Studio 2010 for me, which keeps setting projects seemingly randomly to Client Profile, sometimes when I create a project, and sometimes a few days later. Probably some keyboard shortcut I'm accidentally hitting...

joshcomley
  • 28,099
  • 24
  • 107
  • 147
  • 1
    I'll bet you're right... and shame on me if so for not remembering this comparable question I asked last month! http://stackoverflow.com/questions/3991361/referring-to-code-in-ibm-data-db2-makes-that-assembly-unavailable-to-the-rest-of – Bob Kaufman Nov 26 '10 at 15:46
  • 6
    @Bob It keeps bleedin' happening to me, and just like you having that previous question, each time it happens, for at least a few minutes I'm thoroughly confused by the whole thing until I remember "Oooooh, wait, Client ****ing Profile" – joshcomley Nov 26 '10 at 16:16
  • 4
    I was also having this problem with VS2012. It turned out not to be the Client Profile problem, but that the referenced project was in 4.5 and the new project that referenced had defaulted to 4.0. Bumped that one to 4.5 and problem went away. Same solution really, just another variation. – Brad Mathews Jul 18 '13 at 17:55
  • This happened to me recently in VS 2013. The project was the default 4.5 but one of the libraries was built on 4.5.2. If the project is 4.5.2 and one of the libraries is 4.5 or 4.5.1 it will work. But not the other way around. – ahwm Jan 12 '15 at 15:43
7

Make sure that both projects have same target framework version here: right click on project -> properties -> application (tab) -> target framework

Also, make sure that the project "logger" (which you want to include in the main project) has the output type "Class Library" in: right click on project -> properties -> application (tab) -> output type

Finally, Rebuild the solution.

Manar Gul
  • 289
  • 4
  • 7