我得到一个:

找不到类型或名称空间名称

错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。

有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?

我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?


当前回答

确保您引用的是为项目/文件提供的名称空间。我的问题是,我从另一个项目复制了一个文件,忘记更改名称空间。

其他回答

我不知道为什么这样工作,但我删除了VS2015告诉我它找不到的项目引用,并再次添加它。解决了问题。我尝试过清理、构建和重新启动VS,但都无济于事。

这个方法对我很管用。在定义了类名的类中,例如:公共类ABC,删除一个字符并等待一会儿。您的错误列表将增加,因为您更改了名称。现在把输入的字符放回去。这对我有用,希望对你也有用。祝你好运! !

在我的情况下,我卸载项目,然后:

Opened myProject.csproj and update the ToolsVersion="4.0" to ToolsVersion="12.0"(I'm using vs 2017)(using Paulus's answer https://stackoverflow.com/a/64552201/1594487). Deleted following lines from the myProject.csproj: <Import Project="..\packages\EntityFramework.6.4.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

问题解决了。

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应用程序,但这个问题可能发生在不同类型的项目中。

[Facepalm]我的问题是我在c++的做事方式中添加了依赖。

转到无法构建的项目,在解决方案资源管理器中打开“References”文件夹,查看是否列出了您的依赖项。

如果没有,您可以“添加引用”并在Projects选项卡上选择依赖项。

Shankar繁荣。