31

My application has a mixture of 3.5 and 4.0-targeted assemblies. I'm working on a new Windows service targeting 4.0 and the project suddenly seems unable to see some of the other assemblies in the solution. Meaning, on build, all references to these certain other assemblies produce the following error:

The type or namespace name '[X]' does not exist in the namespace '[Y]' (are you missing an assembly reference?)

If I delete the project reference and re-add it, the red squigglies go away and Intellisense kicks in again like it's supposed to. All of the other projects in the solution build without issue. But as soon as I try to build this new project, the errors come back.

One of the failing references is to our Core.dll, which targets 3.5. We recently added a CoreEx.dll targeting 4.0, with namespace sharing between the assemblies. The new service can see CoreEx.dll but not Core.dll... i.e., when I begin typing using Core.Utilities... Intellisense picks up on the smaller set of namespaces from CoreEx.dll but does not show any that appear only in Core.dll. I'm pretty sure the solution built successfully after adding this, but it's a notable recent change.

Another failing reference is to our core Data.dll which holds a bunch of datasets and Entity Framework stuff. This one was recently migrated to 4.0. Again, I'm almost positive the solution built after migrating the project, but it's worth mentioning.

The last failing reference is an assembly that uses the namespace one level "up" from the service. E.g., the problematic project is based out of namespace ProductName.Component.ComponentService and it is unable to see the project based out of namespace ProductName.Component. This one was recently created along with the problematic project and also targets 4.0.

As you can see, there doesn't seem to be any rhyme or reason to which assembly references are failing... and the problematic project can successfully reference some of the other assemblies in the solution. I've tried cleaning, re-building, restarting Visual Studio... nothing has fixed it permanently. What could be causing this?

Calvin Fisher
  • 4,653
  • 5
  • 36
  • 47
  • I had the simple version of your problem, the live semantic errors (red squigglies) and intellesense support crashed. Re-building doesn't help, but removing the project and adding it back solves the problem. Sounds like you're familiar with this problem... you first re-added the project, then had further problems. Why does the simple version happen? Is there any prevention? It's really annoying! – Stephan Luis Mar 06 '14 at 23:17

7 Answers7

60

Check the target platform of the new project and make sure it's not targeting .NET 4 Client Profile. If it is, change it to regular .NET 4

Dimitri
  • 6,923
  • 4
  • 35
  • 49
  • Good thought, but I already checked for that... edited question to say so too. – Calvin Fisher Apr 29 '11 at 04:07
  • I checked AGAIN because the symptoms were so characteristic of this condition -- [example 1](http://stackoverflow.com/questions/4981204/net-framework-4-client-profile-system-web-dll), [example 2](http://stackoverflow.com/questions/3304741/vs2010-getting-type-or-namespace-name-could-not-be-found-but-everything-seems) [example 3](http://stackoverflow.com/questions/4764978/the-type-or-namespace-name-could-not-be-found) -- and there it was. Perhaps I fat-fingered before and was actually looking at an adjacent project. – Calvin Fisher Apr 29 '11 at 14:50
  • I can't understand why Visual Studio appears to have switched the .NET version like this... I don't remember it being set to that before. Thanks for the solution. – kad81 Aug 20 '12 at 07:02
2

I was adding projects to a Solution that utilized .net 4.5. The projects I had added were defaulting to 4.5.1. This rendered 4.5 libraries incompatible with the new projects. I went into the properties of my new projects and had them target 4.5 instead of the default 4.5.1. After I had done that, my solution was able to build.

1

Are the dependencies set correctly in the solution? I have seen more than one occasion where Project A depends on Project B, but because the dependency between the two was not set the build fails sporadically.

The underlying cause in this case is that the build is order is not deterministic and success/failure depends on things like which projects build (based on what changed) and which builds first (when more than one builds).

DocMax
  • 12,094
  • 7
  • 44
  • 44
  • 1
    When you say dependencies, you mean project references? Also, I've tried manually building the depended-upon projects first, and they build successfully. But manually building the problematic project after that still fails. Also also, the problematic project fails every time now, so it doesn't seem to be a sporadic thing... unless I've misunderstood? – Calvin Fisher Apr 29 '11 at 04:06
0

Please also note it can happen if you change the namespace but you did not changed the Assembly name in the project properties.

Loïc Lopes
  • 544
  • 8
  • 19
0

This problem happened to me once I solved it by deleting all the using statements on top and manually writing them again.

Little Programmer
  • 181
  • 1
  • 5
  • 15
0

I had a similar issue, an assembly reference fail (“Are you missing a using directive or an assembly reference?”) and the VS intellisense gave me the opportunity to add the using but in the solution the reference had the yellow icon and the build was failing.

I solved this looking at the project property Target Framework and changing the .net version to the reference solution version and this solved all problems.

Note: The .net versions should be compatible between projects.

DJon
  • 1
  • 1
0

It worked for me when I changed the target framework to 4.0..But that was not the solution we wanted..We Wanted to use VS 2010 Premium for our project but the intention was NOT to use .net 4.0...The main class library project(.net 2.0) was referencing the dll "system.web.abstractions.dll"...I added the reference to this dll in other projects(.net 2.0) which references the main class library...the solution compiled without any problems...so it could be the case with your visual studio solution...

But everything works fine if we use VS 2008 professional..we need no workaround & everything works like magic...