我得到一个:

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

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

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

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


当前回答

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繁荣。

我们有一个奇怪的例子,我刚刚在溶液中修正了它。在主项目中的“using”语句前有一个隐藏/空白字符。这个项目可以很好地构建,网站也可以很好地运行,但是引用它的单元测试项目不能被构建。

我在试图以代理的身份在本地机器上运行Visual Studio Team Services构建时遇到此错误。

它在我的常规工作空间中工作得很好,我能够在本地代理文件夹中打开SLN文件,一切都编译好了。

有问题的DLL存储在项目中Lib/MyDLL.DLL,并在csproj文件中引用此DLL:

<Reference Include="MYDLL, Version=2009.0.0.0, Culture=neutral, PublicKeyToken=b734e31dca085caa">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>Lib\MYDLL.dll</HintPath>
</Reference>

结果是,尽管有提示路径,它还是找不到文件。我认为msbuild可能是相对于SLN文件而不是项目文件。

在任何情况下,如果您得到的消息是无法解析此引用。无法定位程序集,请确保DLL位于msbuild可访问的位置。

我有点作弊,发现一条消息说“参考\bin\xxx.dll”,然后把dll复制到那里。

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

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

检查你的文件扩展名:

工作在vscode和一直得到相同的错误,但一切工作!彩色编码,智能感知,快速操作,文件夹图标....但出于某种原因,它就是建不起来。

最后浏览本地文件系统,注意到类文件上的文件扩展名丢失了,构建一直抱怨这个问题。