我得到一个:
找不到类型或名称空间名称
错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。
有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?
我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?
我得到一个:
找不到类型或名称空间名称
错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。
有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?
我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?
当前回答
要解决这个问题,还可以删除并重新创建*.sln。关联解决方案的DotSettings文件。
其他回答
I had a similar issue: The compiler was unable to detect a folder inside the same project, so a using directive linking to that folder generated an error. In my case, the problem originated from renaming the folder. Even though I updated the namespace of all the classes inside that folder, the project info somehow failed to update. I tried everything: deleting the .suo file and the bin and obj folders, cleaning the solution, reloading the project - nothing helped. I resolved the problem by deleting the folder and the classes inside, creating a new folder and creating new classes in that new folder (simply moving the classes inside the new folder didn't help).
PS:以我为例,我正在开发一个web应用程序,但这个问题可能发生在不同类型的项目中。
它甚至发生在Visual Studio 2017中。
重启Visual Studio 无法构建的干净项目。 重新构建项目。
有同样的错误,我的故事如下: 在糟糕的合并(通过git)后,我的一个.csproj文件有重复的编译条目,如:
<Compile Include="Clients\Tree.cs" />
<Compile Include="Clients\Car.cs" />
<Compile Include="Clients\Tree.cs" /> //it's a duplicate
如果您有一个大的解决方案,并且错误窗口中有超过300条消息,那么很难检测到这个问题。 所以我已经通过记事本打开了损坏的.csproj文件,并删除了重复的条目。对我来说很管用。
从GAC中删除程序集(C:\WINDOWS\assembly文件夹-选择您的程序集,右键单击并卸载)。因为解决方案使用guid保持引用,如果guid在GAC中,它将继续接受GAC版本进行编译。
我当时正在做VS 2017社区版,CefSharp的金块包也有同样的问题。
包被成功下载并恢复,项目可以构建并成功运行-只是标记表明名称空间无法识别。
我所要做的就是打开参考资料部分,点击其中一个黄色感叹号。
几秒钟后,标记错误就消失了。