我得到一个:

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

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

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

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


当前回答

我不知道为什么这样工作,但我删除了VS2015告诉我它找不到的项目引用,并再次添加它。解决了问题。我尝试过清理、构建和重新启动VS,但都无济于事。

其他回答

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 2019企业版“降级”到VS 2019专业版后开始出现这个问题。 尽管错误显示在“错误”窗口中,但我可以毫无问题地构建项目。 尝试了这个线程和其他线程的许多解决方案,如均衡目标框架,删除并重新引用,删除.suo文件等。 对我来说,有效的方法是删除本地存储库中的项目,并从远程存储库中再次克隆它。

它甚至发生在Visual Studio 2017中。

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

我在试图以代理的身份在本地机器上运行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复制到那里。

在将一些新代码合并到vs2019项目后遇到了同样的问题。 重新启动VS,卸载和重新加载项目,确保解决方案中所有项目ToolsVersion=和TargetFrameworkVersion相同。这些都无济于事。

我有一个项目基板的情况,未能找到名称空间皮肤(在项目皮肤)。

最后我打开了基板。并检查了所有的ProjectReference Include条目。其他的都在那里,但没有对Skin的引用,即使Skin确实显示在小项目依赖对话框的复选框中。因此,项目依赖关系对话框接受了皮肤的复选框(并将其保存在某个地方),但没有改变basis .csproj。然后我手动添加ProjectReference Include,确保我拥有皮肤项目的正确路径和GUID。

< ProjectReference Include = " \ Skin皮肤csproj”>。 < > {1ad4b5d7-5014-4f5f-983e-2c59ac0e0028} < - >项目项目 < Name > Skin - < Name > < / ProjectReference >

然后我保存了基板。Csproj,问题就解决了。正如其他人所说,这是VS工具的一个问题