类型或名称空间名称不存在。

时间:2021-10-08 09:40:10

I have a WCF Data Service project built with Visual Studio 2010, which was working fine. All of a sudden, it didn't compile anymore. It was giving me messages like:

我有一个WCF数据服务项目,它是Visual Studio 2010构建的,运行良好。突然间,它不再编译了。它给我的信息是:

Error 7 The type or namespace name 'Services' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\U...s\Visual Studio 2010\Projects...\DataService.cs ...

错误7在名称空间的系统中不存在类型或名称空间名称“服务”。数据(是否缺少程序集引用?)C:\ U…Visual Studio 2010年代\ \项目…\ DataService。cs……

Error 8 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) DependencyResolver.cs 3 14

错误8名称空间“系统”中不存在类型或名称空间名称“Linq”(是否缺少程序集引用?)DependencyResolver。cs 3 14

Error 10 The type or namespace name 'Web' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)

错误10在名称空间的系统中不存在类型或名称空间名称“Web”。ServiceModel(是否缺少程序集引用?)

Error 12 The type or namespace name 'DataService' could not be found (are you missing a using directive or an assembly reference?)

错误12无法找到类型或名称空间名称“DataService”(您是否缺少使用指令或程序集引用?)

How can I fix it?

我怎样才能修好它?

17 个解决方案

#1


511  

I have had the same problem, and I had to set the "Target Framework" of all the projects to be the same. Then it built fine. On the Project menu, click ProjectName Properties. Click the compile tab. Click Advanced Compile Options. In the Target Framework, choose your desired framework.

我也遇到过同样的问题,我必须将所有项目的“目标框架”设置为相同的。然后它建好。在“项目”菜单上,单击“ProjectName属性”。单击编译选项卡。单击高级编译选项。在目标框架中,选择您想要的框架。

#2


28  

I had an issue with System.Linq not being recognized. The using statement had a red squiggly, etc. The way I solved it was to change my website to target dotnet 3.5, then switch back to the original targeted framework (4.0 in my case).

我对系统有问题。Linq不被认可。我解决的方法是将我的网站改为dotnet 3.5,然后切换回原来的目标框架(在我的例子中是4.0)。

#3


18  

I faced the same issue with an ASP.NET MVC site when I tried to use LINQ to SQL. I fixed the problem by:

我也遇到过同样的问题。当我尝试使用LINQ到SQL时,NET MVC站点。我解决了这个问题:

Solution Explorer -> References -> Right-click on System.Data.Linq -> Copy Local (True)

解决方案资源管理器->引用->右键单击System.Data。Linq ->复制本地(True)

#4


17  

Check to see that your target framework has the same .NET versions. I had the same problem and my class .NET was 3.5 and web solution had 4.5. I synchronised those, and then it worked :)

检查您的目标框架是否有相同的。net版本。我有同样的问题,我的net是3.5,而web解决方案是4.5。我将它们同步,然后它成功了:)

#5


16  

I found that this is caused by me having the same namespace name as class name (MyWorld.MyWorld = Namespace.ClassName).

我发现,这是由于我拥有与类名相同的名称空间名称(MyWorld)。MyWorld = Namespace.ClassName)。

Change your namespace to a name that is not the same name as your class and this will compile.

将名称空间更改为与类不相同的名称,这将编译。

Source

#6


10  

I had the same problem and tried all of the above without any success, then I found out what it was:

我遇到了同样的问题,尝试了以上所有的方法都没有成功,然后我发现了它是什么:

I'd created a folder called "System" in one of my projects and then created a class in it. The problem seems to stem from having a namespace called "System" when the .cs file is created, even if it is in a namespace of "MyProject.System".

我在一个项目中创建了一个名为“系统”的文件夹,然后在其中创建了一个类。当.cs文件被创建时,问题似乎来自于拥有一个名为“System”的名称空间,即使它位于“MyProject.System”的名称空间中。

Looking back I can understand why this would cause problems. It really stumped me at first as the error messages don't initially seem to relate to the problem.

回顾过去,我能理解为什么这会产生问题。起初,它确实让我感到困惑,因为错误消息最初似乎并没有涉及到这个问题。

#7


10  

I have experienced same problem with System.Data.SQLite. The source of the problem is the dll you have used should have same .NET version with your project.

我对System.Data.SQLite也有过同样的问题。问题的根源在于你所使用的dll应该与你的项目有相同的。net版本。

For example if you have used (in my case) SQLite for .NET 4.5, your platform target should be .NET 4.5 too.

例如,如果您在。net 4.5中使用(在我的例子中)SQLite,那么您的平台目标也应该是。net 4.5。

You can find platform target by: Project > (project name) Properties > Build.

您可以通过:Project >(项目名称)属性>构建来找到平台目标。

#8


6  

In my case the problem was happening because the class I created had a namespace that interfered with existing classes. The new class A had namespace zz.yy.xx (by mistake). References to objects in another namespace yy.xx were not compiling in class A or other classes whose namespace was zz.

在我的例子中,问题发生了,因为我创建的类有一个与现有类相冲突的名称空间。新类A有命名空间。yy。xx(误)。对另一个名称空间yy中的对象的引用。在A类或其他类名称空间为zz的类中,xx没有进行编译。

I changed the namespace of class A to yy.xx , which it should have been, and it started working.

我将A类的名称空间改为yy。应该是xx,它开始工作了。

#9


5  

FOR ANYONE WITH LINKED FILES: I had this problem and was using silverlight and the offending file that was throwing this error was a linked file.

对于任何有关联文件的人:我有这个问题,使用silverlight和抛出这个错误的违规文件是一个链接文件。

The error from the compiler told me the error was happening in the project that the file lived in. It ended up that the error was NOT in that project, it was occurring in the project that contained the linked file. That project was missing a reference.

编译器的错误告诉我,文件存在的项目中发生了错误。结果是错误不在那个项目中,它发生在包含链接文件的项目中。那个项目漏掉了一个参考。

#10


1  

In my case there was no change in projects, it just stopped to compile and with "type or namespace name XXX does not exist" and in the complaining class itself intellisense for that XXX namespace/class works fine. The problem was in references indeed!

在我的例子中,项目没有变化,它只是停止编译,并使用“类型或名称空间名称XXX不存在”,并且在抱怨类本身中,对于XXX名称空间/类的工作很好。问题确实在参考文献中!

Steps to reproduce:

重现步骤:

  1. Solution has ProjectA, ProjectB. ProjectA references to third party log4net and it is marked Copy local: true. ProjectB references ProjectA and does not have reference to log4net. Solution compiles fine.

    解决方案已经ProjectA ProjectB。ProjectA引用第三方log4net,并标记为本地:true。ProjectB引用ProjectA并没有引用log4net。运行良好的解决方案。

  2. Change in ProjectA: reference property for log4net to Copy local: false.

    更改项目:log4net的引用属性复制本地:false。

  3. Clean bin and obj folders.
  4. 清理bin和obj文件夹。
  5. When you compile, ProjectA compiles but ProjectB complains about not finding ProjectA namespace.
  6. 当您编译时,ProjectA编译,但是ProjectB抱怨找不到ProjectA名称空间。

This is because ProjectB bin folder is missing third party library (log4net in my case)!

这是因为ProjectB bin文件夹丢失了第三方库(在我的例子中是log4net)!

In this case solution would be -

在这种情况下,解决方案是-。

  1. make sure that third party libraries references are set to Copy local: true or
  2. 确保第三方库引用被设置为复制本地:true或。
  3. add path to such libraries in project properties under reference path.
  4. 在参考路径下的项目属性中添加路径到此类库。

#11


1  

I am referencing Microsoft.CommerceServer.Runtime.Orders and experienced this error. This project is old and has Target framework .NET 2.0. In output I had this error:

我引用Microsoft.CommerceServer.Runtime。订单并经历了这个错误。这个项目是旧的,有目标框架。net 2.0。在输出中,我有这个错误:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3268: The primary reference "Microsoft.CommerceServer.Runtime" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.CommerceServer.Runtime" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

I simply changed the target framework to .NET 4 and now it builds.

我只是将目标框架更改为。net 4,现在它构建了。

#12


1  

And if all else fails, such as ensuring that the target frameworks are the same, and you are dealing with a WPF class library in VS2010, simply restart Visual Studio. That did it for me.

如果其他方法都失败了,比如确保目标框架是相同的,并且在VS2010中处理WPF类库,只需重新启动Visual Studio。这是为了我。

#13


1  

I encountered this problem while using Visual Studio's Git integration to manage the project. For some reason the Windows Phone 8 project would compile just fine when targeting x86, but when I set it to target ARM, it would fail compiling with an error indicating that "Advertising" didn't exist in the Microsoft namespace.

我在使用Visual Studio的Git集成来管理项目时遇到了这个问题。由于某些原因,Windows Phone 8项目在针对x86的时候会很好地编译,但是当我将它设置为目标ARM时,它会失败编译,并显示在Microsoft名称空间中不存在“广告”。

I ended up resolving the issue by removing the Microsoft.Advertising.*.dll reference and adding it again.

我最终解决了这个问题,去掉了微软的广告。dll引用并再次添加它。

#14


0  

I experienced the same errors. After I discovered my project had the wrong Assembly name (I copied files from a different project and the namespaces got a little confused), and changed it back, the project compiled nicely.

我也犯过同样的错误。当我发现我的项目有错误的程序集名称(我从一个不同的项目复制文件,名称空间有点混乱),并将它修改回来,这个项目编译得很好。

#15


0  

I got a very similar error message that was caused by inadvertently having made a duplicate of a class in another project of my solution. Deleting the duplicate fixed the issue

我得到了一个非常类似的错误消息,这是由于在我的解决方案的另一个项目中无意中造成了一个类的重复。删除重复修正的问题。

#16


0  

I recently needed to do a System Restore and it caused several of my files to change/disappear that I had been working on since the restore. Some of those were DLL files. I used Source Control to retrieve the entire project but I still had a similar issue as above. I found this answer that described you may need to remove a DLL and readd it to get your errors fixed. This was the case in my scenario.

我最近需要做一个系统恢复,它导致我的几个文件发生了改变/消失,自从恢复之后我一直在工作。其中有些是DLL文件。我使用源代码控制来检索整个项目,但我仍然有一个类似的问题。我发现这个答案描述了您可能需要删除一个DLL并读取它来修复错误。我的情况就是这样。

Removing WebMatrix.WebData and readding it as well as adding in WebMatrix.Data fixed my error of The type or namespace name 'Data' does not exist in the namespace 'WebMatrix' ....

删除WebMatrix。WebData和readding,以及添加WebMatrix。数据固定我的错误的类型或命名空间名称的数据不存在的名称空间的WebMatrix ....

#17


-3  

Delete the .refresh.dll file if you are under source control. Then rebuild. It should work. This worked for me

删除.refresh。如果你在源代码控制下,dll文件。然后重建。它应该工作。这为我工作

#1


511  

I have had the same problem, and I had to set the "Target Framework" of all the projects to be the same. Then it built fine. On the Project menu, click ProjectName Properties. Click the compile tab. Click Advanced Compile Options. In the Target Framework, choose your desired framework.

我也遇到过同样的问题,我必须将所有项目的“目标框架”设置为相同的。然后它建好。在“项目”菜单上,单击“ProjectName属性”。单击编译选项卡。单击高级编译选项。在目标框架中,选择您想要的框架。

#2


28  

I had an issue with System.Linq not being recognized. The using statement had a red squiggly, etc. The way I solved it was to change my website to target dotnet 3.5, then switch back to the original targeted framework (4.0 in my case).

我对系统有问题。Linq不被认可。我解决的方法是将我的网站改为dotnet 3.5,然后切换回原来的目标框架(在我的例子中是4.0)。

#3


18  

I faced the same issue with an ASP.NET MVC site when I tried to use LINQ to SQL. I fixed the problem by:

我也遇到过同样的问题。当我尝试使用LINQ到SQL时,NET MVC站点。我解决了这个问题:

Solution Explorer -> References -> Right-click on System.Data.Linq -> Copy Local (True)

解决方案资源管理器->引用->右键单击System.Data。Linq ->复制本地(True)

#4


17  

Check to see that your target framework has the same .NET versions. I had the same problem and my class .NET was 3.5 and web solution had 4.5. I synchronised those, and then it worked :)

检查您的目标框架是否有相同的。net版本。我有同样的问题,我的net是3.5,而web解决方案是4.5。我将它们同步,然后它成功了:)

#5


16  

I found that this is caused by me having the same namespace name as class name (MyWorld.MyWorld = Namespace.ClassName).

我发现,这是由于我拥有与类名相同的名称空间名称(MyWorld)。MyWorld = Namespace.ClassName)。

Change your namespace to a name that is not the same name as your class and this will compile.

将名称空间更改为与类不相同的名称,这将编译。

Source

#6


10  

I had the same problem and tried all of the above without any success, then I found out what it was:

我遇到了同样的问题,尝试了以上所有的方法都没有成功,然后我发现了它是什么:

I'd created a folder called "System" in one of my projects and then created a class in it. The problem seems to stem from having a namespace called "System" when the .cs file is created, even if it is in a namespace of "MyProject.System".

我在一个项目中创建了一个名为“系统”的文件夹,然后在其中创建了一个类。当.cs文件被创建时,问题似乎来自于拥有一个名为“System”的名称空间,即使它位于“MyProject.System”的名称空间中。

Looking back I can understand why this would cause problems. It really stumped me at first as the error messages don't initially seem to relate to the problem.

回顾过去,我能理解为什么这会产生问题。起初,它确实让我感到困惑,因为错误消息最初似乎并没有涉及到这个问题。

#7


10  

I have experienced same problem with System.Data.SQLite. The source of the problem is the dll you have used should have same .NET version with your project.

我对System.Data.SQLite也有过同样的问题。问题的根源在于你所使用的dll应该与你的项目有相同的。net版本。

For example if you have used (in my case) SQLite for .NET 4.5, your platform target should be .NET 4.5 too.

例如,如果您在。net 4.5中使用(在我的例子中)SQLite,那么您的平台目标也应该是。net 4.5。

You can find platform target by: Project > (project name) Properties > Build.

您可以通过:Project >(项目名称)属性>构建来找到平台目标。

#8


6  

In my case the problem was happening because the class I created had a namespace that interfered with existing classes. The new class A had namespace zz.yy.xx (by mistake). References to objects in another namespace yy.xx were not compiling in class A or other classes whose namespace was zz.

在我的例子中,问题发生了,因为我创建的类有一个与现有类相冲突的名称空间。新类A有命名空间。yy。xx(误)。对另一个名称空间yy中的对象的引用。在A类或其他类名称空间为zz的类中,xx没有进行编译。

I changed the namespace of class A to yy.xx , which it should have been, and it started working.

我将A类的名称空间改为yy。应该是xx,它开始工作了。

#9


5  

FOR ANYONE WITH LINKED FILES: I had this problem and was using silverlight and the offending file that was throwing this error was a linked file.

对于任何有关联文件的人:我有这个问题,使用silverlight和抛出这个错误的违规文件是一个链接文件。

The error from the compiler told me the error was happening in the project that the file lived in. It ended up that the error was NOT in that project, it was occurring in the project that contained the linked file. That project was missing a reference.

编译器的错误告诉我,文件存在的项目中发生了错误。结果是错误不在那个项目中,它发生在包含链接文件的项目中。那个项目漏掉了一个参考。

#10


1  

In my case there was no change in projects, it just stopped to compile and with "type or namespace name XXX does not exist" and in the complaining class itself intellisense for that XXX namespace/class works fine. The problem was in references indeed!

在我的例子中,项目没有变化,它只是停止编译,并使用“类型或名称空间名称XXX不存在”,并且在抱怨类本身中,对于XXX名称空间/类的工作很好。问题确实在参考文献中!

Steps to reproduce:

重现步骤:

  1. Solution has ProjectA, ProjectB. ProjectA references to third party log4net and it is marked Copy local: true. ProjectB references ProjectA and does not have reference to log4net. Solution compiles fine.

    解决方案已经ProjectA ProjectB。ProjectA引用第三方log4net,并标记为本地:true。ProjectB引用ProjectA并没有引用log4net。运行良好的解决方案。

  2. Change in ProjectA: reference property for log4net to Copy local: false.

    更改项目:log4net的引用属性复制本地:false。

  3. Clean bin and obj folders.
  4. 清理bin和obj文件夹。
  5. When you compile, ProjectA compiles but ProjectB complains about not finding ProjectA namespace.
  6. 当您编译时,ProjectA编译,但是ProjectB抱怨找不到ProjectA名称空间。

This is because ProjectB bin folder is missing third party library (log4net in my case)!

这是因为ProjectB bin文件夹丢失了第三方库(在我的例子中是log4net)!

In this case solution would be -

在这种情况下,解决方案是-。

  1. make sure that third party libraries references are set to Copy local: true or
  2. 确保第三方库引用被设置为复制本地:true或。
  3. add path to such libraries in project properties under reference path.
  4. 在参考路径下的项目属性中添加路径到此类库。

#11


1  

I am referencing Microsoft.CommerceServer.Runtime.Orders and experienced this error. This project is old and has Target framework .NET 2.0. In output I had this error:

我引用Microsoft.CommerceServer.Runtime。订单并经历了这个错误。这个项目是旧的,有目标框架。net 2.0。在输出中,我有这个错误:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3268: The primary reference "Microsoft.CommerceServer.Runtime" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.CommerceServer.Runtime" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

I simply changed the target framework to .NET 4 and now it builds.

我只是将目标框架更改为。net 4,现在它构建了。

#12


1  

And if all else fails, such as ensuring that the target frameworks are the same, and you are dealing with a WPF class library in VS2010, simply restart Visual Studio. That did it for me.

如果其他方法都失败了,比如确保目标框架是相同的,并且在VS2010中处理WPF类库,只需重新启动Visual Studio。这是为了我。

#13


1  

I encountered this problem while using Visual Studio's Git integration to manage the project. For some reason the Windows Phone 8 project would compile just fine when targeting x86, but when I set it to target ARM, it would fail compiling with an error indicating that "Advertising" didn't exist in the Microsoft namespace.

我在使用Visual Studio的Git集成来管理项目时遇到了这个问题。由于某些原因,Windows Phone 8项目在针对x86的时候会很好地编译,但是当我将它设置为目标ARM时,它会失败编译,并显示在Microsoft名称空间中不存在“广告”。

I ended up resolving the issue by removing the Microsoft.Advertising.*.dll reference and adding it again.

我最终解决了这个问题,去掉了微软的广告。dll引用并再次添加它。

#14


0  

I experienced the same errors. After I discovered my project had the wrong Assembly name (I copied files from a different project and the namespaces got a little confused), and changed it back, the project compiled nicely.

我也犯过同样的错误。当我发现我的项目有错误的程序集名称(我从一个不同的项目复制文件,名称空间有点混乱),并将它修改回来,这个项目编译得很好。

#15


0  

I got a very similar error message that was caused by inadvertently having made a duplicate of a class in another project of my solution. Deleting the duplicate fixed the issue

我得到了一个非常类似的错误消息,这是由于在我的解决方案的另一个项目中无意中造成了一个类的重复。删除重复修正的问题。

#16


0  

I recently needed to do a System Restore and it caused several of my files to change/disappear that I had been working on since the restore. Some of those were DLL files. I used Source Control to retrieve the entire project but I still had a similar issue as above. I found this answer that described you may need to remove a DLL and readd it to get your errors fixed. This was the case in my scenario.

我最近需要做一个系统恢复,它导致我的几个文件发生了改变/消失,自从恢复之后我一直在工作。其中有些是DLL文件。我使用源代码控制来检索整个项目,但我仍然有一个类似的问题。我发现这个答案描述了您可能需要删除一个DLL并读取它来修复错误。我的情况就是这样。

Removing WebMatrix.WebData and readding it as well as adding in WebMatrix.Data fixed my error of The type or namespace name 'Data' does not exist in the namespace 'WebMatrix' ....

删除WebMatrix。WebData和readding,以及添加WebMatrix。数据固定我的错误的类型或命名空间名称的数据不存在的名称空间的WebMatrix ....

#17


-3  

Delete the .refresh.dll file if you are under source control. Then rebuild. It should work. This worked for me

删除.refresh。如果你在源代码控制下,dll文件。然后重建。它应该工作。这为我工作