使用Microsoft.Data.Services.Client.dll而不是System.Data.Services.Client.dll导致Azure.StorageClient出现问题

时间:2012-05-20 16:19:54

标签: wcf azure odata

我们有一个使用WCF 5.0和WindowsAzure SDK的项目。

有两个引用Microsoft.Data.Services.Client.dll和System.Data.Services.Client.dll并且它们存在冲突。如果我删除系统DLL(根据this),我无法使用windowsAzure SDK。如果我删除Microsoft DLL,我无法利用WCF的新功能,特别是OData 3.0版。

删除系统DLL引用后:

  

无法转换   'System.Data.Services.Client.SaveChangesOptions [c:\ Program Files   (x86)\ Microsoft WCF数据   Services \ 5.0 \ bin.NETFramework \ Microsoft.Data.Services.Client.dll]'到   'System.Data.Services.Client.SaveChangesOptions'

其他信息:

  

最佳重载方法匹配   'Microsoft.WindowsAzure.StorageClient.TableServiceContext.SaveChangesWithRetries(System.Data.Services.Client.SaveChangesOptions)'   有一些无效的论点

     

定义了'System.Data.Services.Client.DataServiceContext'类型   在未引用的程序集中。您必须添加引用   assembly'System.Data.Services.Client,Version = 3.5.0.0,   Culture = neutral,PublicKeyToken = b77a5c561934e089'。

如果我删除对Microsoft.Data.Services.Client的引用并添加对System.Data.Services.Client的引用,那么我们没有错误 - 我们也没有得到WCF 5.0!

2 个答案:

答案 0 :(得分:2)

我能够很快地重现这个问题。 Microsoft.WindowsAzure.StorageClient.Dll对System.Data.Service.Client.Dll具有直接引用依赖性,如下所示,因此,如果您要使用Azure Storage Client API,则必须引用System.Data.Service.Client.Dll在您的应用程序中,确保您不能使用WCF 5.0 SDK提供的oData 3.0。更多信息发布在以下SO问题中:

WCF 5.0 and oData 3.0 API not work with azure table storage

答案 1 :(得分:0)

您可以使用 extern别名来区分两个类型名称,这两个名称与包含它们的程序集完全相同。

  1. 为System.Data.Services.Client设置别名 - 比如SystemDataV4

    (见MSDN Blogs - Extern Alais Walkthrough

  2. 在.cs文件的最顶部使用

    extern别名SystemDataV4;

  3. 然后你可以拥有

    using SystemDataV4.System.Data.Services.Client;
    

    serviceContext.SaveChangesWithRetries(SystemDataV4.System.Data.Services.Client.SaveChangesOptions.ReplaceOnUpdate);
    

    注意带有别名的命名空间的前缀,例如:的 SystemDataV4 .System.Data.Services ...