我得到一个:

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

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

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

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


当前回答

在我的VS2019解决方案中添加了一个新的库项目后,我得到了“使用系统”的错误。添加包Newtonsoft. json (currentversion)到库项目修复了这个问题,因为对Newtonsoft的依赖。Json包含了NETStandard。库的依赖项下的库,并正在生成一个警告图标。主项目有一个错误,直到我安装了Newtonsoft。Json,所以我认为它也适用于库;它确实做到了。

其他回答

首先,我将验证您的项目生成的信息是否损坏。在解决方案上进行清理和重新构建。

如果这还不起作用,我在过去看到的一种解决设计器问题的方法是打开一个windows窗体项目,然后再次关闭它。这有点像鸡内脏,所以别抱太大希望。

在我的案例中,我有一个由外部依赖(xsd2code)构建的文件,不知为何它的designer.cs文件没有被VS正确处理。在Visual Studio中创建一个新文件并将代码粘贴进去,这对我来说很管用。

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的金块包也有同样的问题。

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

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

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