我得到一个:

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

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

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

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


当前回答

我的情况和这里讨论的一样,但在我移除系统之前没有解决它。来自引用列表的核心引用(没有它一切都可以正常工作)

希望这能帮助到一些人,因为这个问题很令人沮丧

其他回答

把我的解决方案加入到混合中,因为它有点不同,我花了一段时间来弄清楚。

In my case I added a new class to one project but because my version control bindings weren't set I needed to make the file writable outside of Visual Studio (via the VC). I had cancelled out of the save in Visual Studio but after I made the file writable outside VS I then hit Save All again in VS. This inadvertently caused the new class file to not be saved in the project..however..Intellisense still showed it up as blue and valid in the referencing projects even though when I'd try to recompile the file wasn't found and got the type not found error. Closing and opening Visual Studio still showed the issue (but if I had taken note the class file was missing upon reopening).

当我意识到这一点时,解决方法很简单:将项目文件设置为可写,将丢失的文件读入项目。现在都建好了。

您还可以尝试删除您认为有问题的代码,并查看是否在没有引用该代码的情况下进行编译。如果不是,请修复问题,直到它再次编译,然后将您怀疑的问题代码重新插入。有时,当编译器不喜欢其他东西时,我就会得到一些我知道是正确的类或方法的奇怪错误。一旦我修复了它真正挂起来的东西,这些“幻影”错误就消失了。

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

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

要解决这个问题,还可以删除并重新创建*.sln。关联解决方案的DotSettings文件。

它甚至发生在Visual Studio 2017中。

重启Visual Studio 无法构建的干净项目。 重新构建项目。