Getting “type or namespace name could not be found

2018-12-31 19:51发布

I'm getting a:

type or namespace name could not be found

error for a C# WPF app in VS2010. This area of code was compiling fine, but suddenly I'm getting this error. I've tried removing the Project Reference and the using statement, shutting VS2010 and restarting, but still I have this issue.

Any ideas why this might be occurring, where it seems like I'm doing the right thing re Reference & using statement?

I also noted in VS2010 that intellisense for that namespace is working ok, so it seems like VS2010 has the project reference and is seeing the namespace on one hand, but during compile doesn't see it?

30条回答
还给你的自由
2楼-- · 2018-12-31 20:29

This one worked for me. In your class, where the class name is defined, eg: Public class ABC, remove one character and wait a little. You error list will increase because you have changed the name. Now put back the character that you have typed. This worked for me, hopefully it will work for you too. Good Luck!!!

查看更多
裙下三千臣
3楼-- · 2018-12-31 20:29

I encountered this problem when upgrading existing projects from VS2008 to VS2012. I found that two projects (the only two that I created) were targeting different .Net Frameworks (3.5 and 4.0). I resolved this on the Application tab of the projects by making sure that both projects had ".NET Framework 4" in the Target Framework box.

查看更多
牵手、夕阳
4楼-- · 2018-12-31 20:31

I had same problem as discussed: VS 2017 underlines a class in referenced project as error but the solution builds ok and even intellisense works.

Here is how I managed to solve this issu:

  1. Unload the referenced project
  2. Open .proj file in VS ( i was looking for duplicates as someone suggested here)
  3. Reload project again (I did not change or even save the proj file as I did not have any duplicates)
查看更多
君临天下
5楼-- · 2018-12-31 20:31

You might also try eliminating the code you think you're having problems with and seeing if it compiles with no references to that code. If not, fix things until it compiles again, and then work your suspected problem code back in. Sometimes I get strange errors about classes or methods that I know are correct when the compiler doesn't like something else. Once I fix the thing that it's really getting hung up on, these 'phantom' errors disappear.

查看更多
旧人旧事旧时光
6楼-- · 2018-12-31 20:31

To solve this issue it can also help to delete and recreate the *.sln.DotSettings file of the associated solution.

查看更多
梦醉为红颜
7楼-- · 2018-12-31 20:33

My case was same as discussed here but nothing solved it until I've removed the System.Core reference from the references list (Everything worked fine without it)

hope it will help someone because this issue is quite frustrating

查看更多
登录 后发表回答