Weird: C# Type or Namespace name could not be foun

2019-04-03 03:20发布

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?

10条回答
啃猪蹄的小仙女
2楼-- · 2019-04-03 03:47

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

查看更多
【Aperson】
3楼-- · 2019-04-03 03:48

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.

查看更多
爷、活的狠高调
4楼-- · 2019-04-03 03:49

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.

查看更多
唯我独甜
5楼-- · 2019-04-03 04:02

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

查看更多
Anthone
6楼-- · 2019-04-03 04:02

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

查看更多
我命由我不由天
7楼-- · 2019-04-03 04:04

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.

查看更多
登录 后发表回答