2017-09-13 83 views
0

按照本文(https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet)中的步骤创建,我创建一个控制台应用程序,并添加以下代码的主要方法:错误天青表使用C#

  string connection = "DefaultEndpointsProtocol=https;AccountName=MyStorageAccountName;AccountKey=MyAccountKey;EndpointSuffix=core.windows.net"; 

     CloudStorageAccount account; 
     if (!CloudStorageAccount.TryParse(connection, out account)) 
     { 
      throw new Exception("Unable to parse storage account connection string."); 
     } 

     CloudTableClient tableClient = account.CreateCloudTableClient(); 
     CloudTable table = tableClient.GetTableReference("mytable"); 

     // this is the line at which I get the error: 
     table.CreateIfNotExists(); 

然而,我上执行时有以下错误最后一行:

无法加载文件或程序集“Microsoft.Data.OData,版本= 5.6.2.0,文化=中性公钥= 31bf3856ad364e35”或它的一个依赖。定位的程序集清单定义与程序集引用不匹配。 (异常来自HRESULT:0x80131040)

任何想法,为什么我得到这个错误?

注:我写了类似的代码,目标是相同的存储帐户,但创建一个队列,它工作正常。

回答

0

它看起来应该删除解决方案的包文件夹,并清理和重建项目。另外请确保实际安装了Microsoft.Data.OData nuget包。:)

0

任何想法,为什么我得到这个错误?

既然你已经安装了WindowAzure.Storage(版本8.4.0)包,它的依赖命名Microsoft.Data.OData(5.8.2版本)中的一个也将安装。可能有其他一些引用Microsoft.Data.OData(版本5.6.2)的软件包,它会引起你在文章中提到的异常。

要解决此问题,可以在配置文件(app.config)中添加assemblyBinding。它会将Microsoft.Data.OData的所有依赖关系绑定到您安装的程序集。 assemblyBinding的格式如下所示。

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.8.3.0" newVersion="5.8.3.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.8.3.0" newVersion="5.8.3.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.8.3.0" newVersion="5.8.3.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration>