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

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 ... 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 Error 10 The type or namespace name 'Web' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?) Error 12 The type or namespace name 'DataService' could not be found (are you missing a using directive or an assembly reference?)

我该怎么解决呢?


当前回答

我得到了一个非常类似的错误消息,这是由于无意中在我的解决方案的另一个项目中创建了一个类的副本而引起的。删除副本解决了这个问题

其他回答

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

我正在引用Microsoft.CommerceServer.Runtime.Orders并遇到此错误。这个项目是旧的,有目标框架。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"

我简单地将目标框架更改为. net 4,现在就可以构建了。

我在System.Data.SQLite中也遇到了同样的问题。问题的根源是您所使用的dll应该与您的项目具有相同的. net版本。

例如,如果你在。net 4.5上使用了SQLite(在我的情况下),那么你的平台目标也应该是。net 4.5。

您可以通过以下方式找到平台目标:项目>(项目名称)属性> Build。

我得到了一个非常类似的错误消息,这是由于无意中在我的解决方案的另一个项目中创建了一个类的副本而引起的。删除副本解决了这个问题

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