我得到一个:

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

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

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

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


当前回答

检查包含缺失类型的.cs文件的构建操作。确保它是c#编译器。

单击包含缺失类型的.cs文件。 按F4调出Properties。 确保构建动作设置为c#编译器。

之前:

后:

其他回答

我在将现有项目从VS2008升级到VS2012时遇到了这个问题。我发现有两个项目(我只创建了两个)针对的是不同的. net框架(3.5和4.0)。我在项目的Application选项卡上解决了这个问题,确保两个项目都有“。NET Framework 4”中的目标框架。

我知道这是踢死马,但我有这个错误和框架在哪里好。我的问题基本上是声明无法找到接口,但它构建和访问都很好。所以我开始思考:“为什么只有这个界面,而其他人都工作得很好?”

最终,我使用WCF的端点接口访问了一个服务,该端点接口使用的是实体版本6,而其余的项目使用的是版本5。我没有使用NuGet,而是简单地将NuGet包复制到本地存储库以供重用,并以不同的方式列出它们。

例如,EntityFramework6.dll vs . EntityFramework.dll。

然后,我将引用添加到客户端项目,噗的一声,我的错误消失了。我意识到这是一个边缘情况,因为大多数人不会混合实体框架的版本。

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

我当时正在做VS 2017社区版,CefSharp的金块包也有同样的问题。

包被成功下载并恢复,项目可以构建并成功运行-只是标记表明名称空间无法识别。

我所要做的就是打开参考资料部分,点击其中一个黄色感叹号。

几秒钟后,标记错误就消失了。

我在项目资源管理器中打开项目下面的引用,将鼠标悬停在其中一个缺失的引用上,很快,它就找到了所有东西。然后我就可以成功地建造了。

运行Visual Studio Community 2019,版本16.8.4