我得到一个:

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

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

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

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


当前回答

对于那些在试图将网站发布到Azure时遇到这种错误的人来说,上面这些看起来很有希望的解决方案都没有帮助到我。我也在同一条船上——我的解决方案本身构建得很好。最后我不得不这么做

把我溶液里的鸡块都去掉。 关闭并重新打开我的溶液。 重新添加所有的nuget包。

有点痛苦,但这是我能让我的网站发布到Azure的唯一方法。

其他回答

我遇到了同样的问题:VS 2017强调引用项目中的一个类为错误,但解决方案构建正常,甚至智能感知工作。

下面是我解决这个问题的方法:

卸载引用的项目 在VS中打开。proj文件(我正在寻找重复的人建议在这里) 重新加载项目(我没有改变甚至保存proj文件,因为我没有任何副本)

对于那些在试图将网站发布到Azure时遇到这种错误的人来说,上面这些看起来很有希望的解决方案都没有帮助到我。我也在同一条船上——我的解决方案本身构建得很好。最后我不得不这么做

把我溶液里的鸡块都去掉。 关闭并重新打开我的溶液。 重新添加所有的nuget包。

有点痛苦,但这是我能让我的网站发布到Azure的唯一方法。

在我的例子中,我发现VisualStudio中的引用有一个三角形和一个感叹号,就像这个图像,

然后,我右键单击删除它,并正确地添加dll引用,问题就解决了。

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

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

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).

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