29

I have a weird error showing up in my project when it is open in the VS2012 IDE. Everywhere where I make use of another referenced project it suddenly says "Type or Namespace name could not be found". And by "says", I mean it has the text underlined in red with the error when I hover over it. The intellisense doesn't work for that code. BUT (and here's the weird part), the errors do not show up in the error console and the project builds and runs fine.

I can even debug and step through the code and it works perfectly fine. So at runtime the project is referenced fine but at design time the IDE can't find it. This worked for the past 2 weeks, and only then suddenly went a little bonkers. It's really annoying because I am rubbish at coding without intellisense!

Has anybody ever seen anything like this or have any suggestions?

9
  • have you checked the Output window?
    – DiskJunky
    Commented Mar 13, 2013 at 19:48
  • Try building just the referenced projects. Does that help? Commented Mar 13, 2013 at 19:49
  • The output window while building shows nothing interesting. When not building it just shows nothing. Commented Mar 13, 2013 at 19:50
  • 2
    Shot in the dark: Are you using ReSharper? Try closing the solution, and deleting the _ReSharper* directories beneath your solution directory, then reopening the solution. Commented Mar 13, 2013 at 19:52
  • This might help stackoverflow.com/questions/3304741/… Commented Mar 13, 2013 at 19:52

10 Answers 10

14

I had this. I referenced assemblies whose "Target Framework" were set to ".Net Framework 4" in the "Application" secion of the projects properties. I changed this to ".Net Framework 4.5" not just in the referenced assembly's project but also the project I was building and it worked. Give this a try.

3
  • 1
    Thanks, this may help other users with the same problem, but in my instance all the projects already used 4.5. @TejasSharma already suggested it. Commented Sep 11, 2013 at 22:01
  • This is what I ran into as well. Would have been nice if the error about 'target frameworks do not match' would have appeared as opposed to not finding the reference.
    – atconway
    Commented Jan 3, 2014 at 21:09
  • 1
    My DLL was built for Framework 4.5, and the app I was trying to use it was built for Framework 4. After rebuilding the DLL for the older framework, it worked again.
    – Triynko
    Commented Jul 3, 2014 at 20:41
11

I have found this is a known problem with VS2012. Check to see how you are building, 64 bit or 32 bit. It won't work with 64 bit but it will with 32 bit. It will say things are missing and design will not work, however the program will run fine. I have heard the new VS update that hasn't been released yet will fix it.

11
  • Hi, thanks, but can you elaborate a bit about what to check for and how to fix it? Commented Mar 13, 2013 at 19:55
  • Sure, If you right click your project and go to properties there is a build tab. What you are looking for is called platform target. x86 works with designer x64 does not.
    – Lainezor
    Commented Mar 13, 2013 at 20:00
  • Ok but my development machine as well as the server is x64. Will this not have an effect? Commented Mar 13, 2013 at 20:07
  • And, does the referenced libraries also need to be built in x86? Commented Mar 13, 2013 at 20:08
  • 2
    I just had this happen to me on VS2015 RC so it's still not fixed. The workaround does the job though.
    – Ramón
    Commented May 19, 2015 at 2:57
5

Manually delete all the references to the libraries of the other projects and re-add. Intellisense rebuilds whatever it needs at that point and doing this has helped me in the past.

1
  • Yes, this did it for me too -- I removed the reference to the other project that provided the type underlined in red, kicked off a build (showing some real build errors this time), then re-added the other project and rebuilt. I had formerly blamed Resharper for the error but it persisted even after uninstalling Resharper, so it appears to be a pure Visual Studio bug. It popped up soon after upgrading from 15.4 to 15.5.
    – Ed Avis
    Commented Dec 7, 2017 at 20:45
3

Another source of this problem is a solution with multiple projects containing code for the same namespace. The compiler can handle this. Intellisense won’t.

3

Related to a couple other answers here, I had a "Data" project using a "Data" namespace. Built fine, but just started recently showing errors from intellisense (even though it continued building fine.) (VS 2015.)

I fixed this by changing my "Data" project and namespace to "MyCompany.Data".

Oddly, the problem didn't seem to show up until recently, but making the change did fix it. Presumably there was a conflict in namespace with another project or reference, which can build fine, but intellisense can't handle.

You can change this in the Application tab of Project properties. You can also open up an EDMX diagram, right click, choose model browser, choose the second collapsable item in the model browser tab, hit properties, and there you'll find the Namespace option for generated Entity Framework entities and contexts. (Similiarly, if you modify an Entity Framework Model's namespace, you might also need to change the related connection to match [in Web.Config for ASP.Net and MVC.])

1
  • This fixed my issue.
    – ttugates
    Commented Nov 9, 2017 at 15:55
1

Make sure that there is no class with the name same as Project default namespace.

1

make sure that you don't reference .net framework 4.5 projects in .net 4 projects!

2
  • 2
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.
    – Wouter J
    Commented Mar 14, 2013 at 21:40
  • as I understood the problem, and from former experience with vs2012 ide - I believed that this is the answer (I wouldn't answer it if not). Will consider the post comment next time. thanks Commented Mar 14, 2013 at 21:53
1

Examine your .proj files in a text editor and make sure the paths to your references are correct.

0

This can also happen if you set the Build Action to "None" on the referenced file and forget about it.

0

I had the same problem, where it would build and run fine, it just would always show that error and I couldn't use intellisense with the class.

I actually used the automatic method of creating the class in a new file to resolve the issue, then just copied the code over from the real class. I deleted the old file, renamed the new file, and now it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.