c# - 开发期间访问 Azure 存储时无法加载程序集 'Microsoft.Data.OData'

标签 c# visual-studio-2010 azure azure-storage

我在 Visual Studio 中创建了一个简单的 C# 应用程序,并尝试从本地计算机运行该应用程序。我有 Visual Studio 2013。但是,当我尝试运行该程序时,出现异常: 无法加载文件或程序集“Microsoft.Data.OData,Version=5.6.0.0,Culture=neutral

我也尝试过这里提到的解决方案:Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table Storage

即在我的配置文件中添加以下内容:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

但是还是没有成功。我不知道是否应该对该文本的版本进行任何更改。

抛出异常的行是:

    CloudTableClient client = storageAccount.CreateCloudTableClient();

我还下载了这个包:http://www.nuget.org/packages/Microsoft.Data.Services.Client/Missing Microsoft.Data.Services.Client version 5.6 on Azure Websites所述。然而安装程序告诉我,我已经拥有该文件的 5.6.1.0 版本,但没有任何反应。

Microsoft.WindowsAzure.Storage.StorageException was unhandled   HResult=-2146233088   Message=Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)   Source=Microsoft.WindowsAzure.Storage   StackTrace:
       at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
       at Microsoft.WindowsAzure.Storage.Table.TableOperation.Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
       at Microsoft.WindowsAzure.Storage.Table.CloudTable.Execute(TableOperation operation, TableRequestOptions requestOptions, OperationContext operationContext)
       at UserConsoleProject2.Program.connectionAzureStorage() in c:\Users\user\Documents\Visual Studio 2013\Projects\UserConsoleProject2\UserConsoleProject2\Program.cs:line 42
       at UserConsoleProject2.Program.Main(String[] args) in c:\Users\user\Documents\Visual Studio 2013\Projects\UserConsoleProject2\UserConsoleProject2\Program.cs:line 419   InnerException: System.IO.FileLoadException
       HResult=-2146234304
       Message=Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
       Source=Microsoft.WindowsAzure.Storage
       FileName=Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
       FusionLog==== Pre-bind state information === LOG: DisplayName = Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35  (Fully-specified) LOG: Appbase = file:///C:/Users/user/Documents/Visual Studio 2013/Projects/UserConsoleProject2/UserConsoleProject2/bin/Debug/ LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.WindowsAzure.Storage, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
=== LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\user\Documents\Visual Studio 2013\Projects\UserConsoleProject2\UserConsoleProject2\bin\Debug\UserConsoleProject2.exe.Config LOG: Using host configuration file:  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/user/Documents/Visual Studio 2013/Projects/UserConsoleProject2/UserConsoleProject2/bin/Debug/Microsoft.Data.OData.DLL. WRN: Comparing the assembly name resulted in the mismatch: Build Number ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

       StackTrace:
            at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpWebRequestFactory.BuildRequestForTableOperation(Uri uri, UriQueryBuilder builder, IBufferManager bufferManager, Nullable`1 timeout, TableOperation operation, Boolean useVersionHeader, OperationContext ctx, TablePayloadFormat payloadFormat, String accountName)
            at Microsoft.WindowsAzure.Storage.Table.TableOperation.<>c__DisplayClass18.<RetrieveImpl>b__15(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, Boolean useVersionHeader, OperationContext ctx)
            at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ProcessStartOfRequest[T](ExecutionState`1 executionState, String startLogMessage)
            at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
       InnerException:

如何让我的程序运行?

最佳答案

我也遇到了同样的问题。我通过确保从 NuGet 安装了以下库版本来使其正常工作:

Microsoft.Windows.Azure.Configuration 2.0.0.0
Microsoft.Windows.Azure.Storage 4.1.0.0
Microsoft.Data.Edm 5.6.1.0
Microsoft.Data.OData 5.6.1.0
Microsoft.Data.Services.Client 5.6.1.0
System.Spatial 5.6.1.0

然后我更改了 app.config 以包含以下内容:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.6.0.0" newVersion="5.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

请注意,引用的程序集是版本 5.6.1.0,而 app.config 引用的是 5.6.0.0。我不知道为什么会这样。

关于c# - 开发期间访问 Azure 存储时无法加载程序集 'Microsoft.Data.OData',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24553176/

相关文章:

c# - 为什么对于 C# 中 byte[] 类型的键,哈希表不会为 "ContainsKey"返回 true?

c++ - 链接 : fatal error LNK1104: cannot open file 'msmpi.lib' visual studio 2010

c# - 参数 "Version 3"的 ConnectionString 格式无效

c# - EPPlus:.Net Core 3.1 Azure 函数中找不到 System.Text.Encoding.CodePages.dll

c# - IRequiresSessionState 与 IReadOnlySessionState

C# : Number Conversion Problem

sql-server - 如何使用 FTP 任务为 SSIS 包配置 Azure VM

java - 微软Azure : how get md5-hash of a blob in Java

c# - 对于任何给定的最大宽度和最大高度,根据纵横比计算宽度和高度

c++ - 谁对谁错又名 GCC vs Visual Studio