我得到一个:

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

错误的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).

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

其他回答

我知道这是踢死马,但我有这个错误和框架在哪里好。我的问题基本上是声明无法找到接口,但它构建和访问都很好。所以我开始思考:“为什么只有这个界面,而其他人都工作得很好?”

最终,我使用WCF的端点接口访问了一个服务,该端点接口使用的是实体版本6,而其余的项目使用的是版本5。我没有使用NuGet,而是简单地将NuGet包复制到本地存储库以供重用,并以不同的方式列出它们。

例如,EntityFramework6.dll vs . EntityFramework.dll。

然后,我将引用添加到客户端项目,噗的一声,我的错误消失了。我意识到这是一个边缘情况,因为大多数人不会混合实体框架的版本。

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

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

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

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

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

在我的情况下,我卸载项目,然后:

Opened myProject.csproj and update the ToolsVersion="4.0" to ToolsVersion="12.0"(I'm using vs 2017)(using Paulus's answer https://stackoverflow.com/a/64552201/1594487). Deleted following lines from the myProject.csproj: <Import Project="..\packages\EntityFramework.6.4.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

问题解决了。

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