我得到一个:
找不到类型或名称空间名称
错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。
有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?
我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?
我得到一个:
找不到类型或名称空间名称
错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。
有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?
我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?
当前回答
重新安装nuget包对我来说很有用。在我将. net Framework版本更改为与所有项目同步后,一些nuget包(特别是Entity Framework)仍然为以前的版本安装。这个命令在包管理器控制台中为整个解决方案重新安装包:
Update-Package –reinstall
其他回答
我们有一个奇怪的例子,我刚刚在溶液中修正了它。在主项目中的“using”语句前有一个隐藏/空白字符。这个项目可以很好地构建,网站也可以很好地运行,但是引用它的单元测试项目不能被构建。
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应用程序,但这个问题可能发生在不同类型的项目中。
在我的例子中,我有一个在适当的源文件夹中列出的类,但没有在解决方案资源管理器中注册。我必须右键单击项目>添加现有项目,手动选择它说它缺少的类。然后一切都运转正常!
检查包含缺失类型的.cs文件的构建操作。确保它是c#编译器。
单击包含缺失类型的.cs文件。 按F4调出Properties。 确保构建动作设置为c#编译器。
之前:
后:
从GAC中删除程序集(C:\WINDOWS\assembly文件夹-选择您的程序集,右键单击并卸载)。因为解决方案使用guid保持引用,如果guid在GAC中,它将继续接受GAC版本进行编译。