我得到一个:

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

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

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

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


当前回答

重新安装nuget包对我来说很有用。在我将. net Framework版本更改为与所有项目同步后,一些nuget包(特别是Entity Framework)仍然为以前的版本安装。这个命令在包管理器控制台中为整个解决方案重新安装包:

Update-Package –reinstall

其他回答

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

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')" />

问题解决了。

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

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

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

重新安装nuget包对我来说很有用。在我将. net Framework版本更改为与所有项目同步后,一些nuget包(特别是Entity Framework)仍然为以前的版本安装。这个命令在包管理器控制台中为整个解决方案重新安装包:

Update-Package –reinstall

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

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

我也有同样的问题。一天晚上,我的项目会在第二天早上编译错误!

我最终发现visual studio决定“调整”我的一些参考,并将它们指向其他地方。例如:

system。componentmodel。isupportinitialize变成了blahblah。system。componentmodel。isupportinitialize

如果你和我一样,我这样做是很粗鲁的