C语言 无法使用表存储在 Azure 云工作角色中加载文件或程序集 Microsoft.Data.OData Version=5.2.0.0 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16908384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:34:03  来源:igfitidea点击:

Could not load file or assembly Microsoft.Data.OData Version=5.2.0.0 error in Azure Cloud Worker Role using Table Storage

cazureazure-storageazure-table-storage

提问by Ryk

I have a very peculiar issue using Azure Table Storage. I have a .NET 4.5 project in Visual Studio 2012 where I deal with all my Azure Table Storage functions. This project/dll is referenced by two other projects, my MVC website, and my Azure Worker Role. (I am running under the Azure Emulators on my machine, but it also happens when I deploy it to the cloud)

我在使用 Azure 表存储时遇到了一个非常奇怪的问题。我在 Visual Studio 2012 中有一个 .NET 4.5 项目,我在其中处理所有 Azure 表存储功能。此项目/dll 被其他两个项目、我的 MVC 网站和我的 Azure 工作角色引用。(我在机器上的 Azure 模拟器下运行,但在我将其部署到云时也会发生这种情况)

I have the following function that is called when I save or retrieve a record:

我在保存或检索记录时调用了以下函数:

internal static CloudTable GetTable(CloudStorageAccount storageAccount, string tableReference)
{
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

    CloudTable table = tableClient.GetTableReference(tableReference);
    table.CreateIfNotExists();

    return tableClient.GetTableReference(table.Name);
}

In my MVC website I have a function that will save a record to a Azure Storage table, and then in my Azure Worker Role there is a service that will read the record.

在我的 MVC 网站中,我有一个将记录保存到 Azure 存储表的函数,然后在我的 Azure 工作角色中有一个服务可以读取该记录。

So both uses the same dll for storage and retrieval, however my MVC project has no issues saving the record, but in my Azure Worker role service when it tries to retrieve the record throws the exception when it attempts to execute "table.CreateIfNotExists();".

因此,两者都使用相同的 dll 进行存储和检索,但是我的 MVC 项目在保存记录时没有问题,但是在我的 Azure Worker 角色服务中,当它尝试检索记录时会在尝试执行“table.CreateIfNotExists() 时抛出异常” ;”。

Could not load file or assembly 'Microsoft.Data.OData, Version=5.2.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)

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

I have done the following already:

我已经做了以下事情:

  1. Updated all the NuGet packages from the solution level to the latest versions
  2. I went through every project reference to make sure that there are no old dll's or previous versions hanging around, in particular the System.Spatial, Microsoft.WindowsAzure.Configuration, Microsoft.WindowsAzure.ServiceRuntime and Microsoft.ServiceBus, Microsoft.WindowsAzure.Storage, Microsoft.Data.Edm & Microsoft.Data.OData
  3. I have even created a new Cloud Service and WorkerRole project from scratch to make sure it is not something in the current WorkerRole project that is broken.
  1. 将所有 NuGet 包从解决方案级别更新到最新版本
  2. 我检查了每个项目参考以确保没有旧的 dll 或以前的版本,特别是 System.Spatial、Microsoft.WindowsAzure.Configuration、Microsoft.WindowsAzure.ServiceRuntime 和 Microsoft.ServiceBus、Microsoft.WindowsAzure.Storage, Microsoft.Data.Edm 和 Microsoft.Data.OData
  3. 我什至从头开始创建了一个新的 Cloud Service 和 WorkerRole 项目,以确保它不会在当前的 WorkerRole 项目中被破坏。

I have not rolled the dll's back to 5.2 as I had too many issues in other projects where I use features that are specific from 5.3 onwards.

我没有将 dll 回滚到 5.2,因为我在其他项目中遇到了太多问题,在这些项目中我使用了 5.3 以后的特定功能。

I am currently running all the dll's on 5.5.

我目前正在 5.5 上运行所有 dll。

When I run the AsmSpy.exe utility found here, I get the following output that I am not 100% sure how to interpret.

当我运行这里找到的 AsmSpy.exe 实用程序时,我得到以下输出,但我不是 100% 确定如何解释。

> Reference: Microsoft.Data.Edm
>         5.5.0.0 by Microsoft.Data.OData
>         5.5.0.0 by Microsoft.Data.Services.Client
>         5.5.0.0 by Microsoft.WindowsAzure.ActiveDirectory.GraphHelper.2013_04_05
> Reference: System.Spatial
>         5.5.0.0 by Microsoft.Data.OData
>         5.5.0.0 by Microsoft.Data.Services.Client Reference: Microsoft.Data.OData
>         5.5.0.0 by Microsoft.Data.Services.Client
>         5.2.0.0 by Microsoft.WindowsAzure.Storage   <-- THIS SEEMS TO BE THE ONE THAT IS CAUSING ISSUES

How I interpret it, is that the Microsoft.WindowsAzure.Storage dll is referencing V 5.2.0.0 of the Microsoft.Data.OData dll, but how do I fix this, if this is the issue? According to the documentation I have seen on the Storage dll is that it is supposed to reference 5.4 and up, not 5.2...?

我如何解释它,Microsoft.WindowsAzure.Storage dll 是否引用了 Microsoft.Data.OData dll 的 V 5.2.0.0,但如果这是问题,我该如何解决?根据我在 Storage dll 上看到的文档,它应该引用 5.4 及更高版本,而不是 5.2...?

回答by astaykov

Opening issue for such an easy to solve issue will not help you.

为这样一个容易解决的问题打开问题对您没有帮助。

Put the following addition configuration in your respective config files (web.config for the MVC and app.config for the worker role):

将以下附加配置放在您各自的配置文件中(MVC 的 web.config 和辅助角色的 app.config):

 <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>

Note that runtimesection is direct descendant of the configurationroot element! I'm pretty sure you already have this section in your web.config, because MVC4 uses it to rebind all references to System.Web.MVCto the latest version.

请注意,runtimesection 是configuration根元素的直接后代!我很确定您的 web.config 中已经有了这个部分,因为 MVC4 使用它来重新绑定System.Web.MVC对最新版本的所有引用。

I personally do not expect the SDK to be updated with every new version of every referenced library! This would be madness...

我个人不希望每个引用库的每个新版本都更新 SDK!这将是疯狂的......

回答by Ben Whittle

I had a very similar problem but in this case it exception message was;

我有一个非常相似的问题,但在这种情况下,它的异常消息是;

Could not load file or assembly 'Microsoft.Data.OData, Version=5.5.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)

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

note it was trying to load v5.5.0.0 of the OData assembly.

请注意,它正在尝试加载 OData 程序集的 v5.5.0.0。

After some digging around with ILSpy (http://www.ilspy.net) I discovered that Microsoft.WindowsAzure.Storage 2.0.0.0 was explictly referencing Microsoft.Data.OData 5.2.0.0 - which I didn't have as my version was 5.5.0.0.

在使用 ILSpy ( http://www.ilspy.net)进行一些挖掘后,我发现 Microsoft.WindowsAzure.Storage 2.0.0.0 明确引用了 Microsoft.Data.OData 5.2.0.0 - 我没有因为我的版本是5.5.0.0。

So the solution was to use the NuGet package manager to uninstall Microsoft.WindowsAzure.Storage, this inturn uninstalled Microsoft.Data.OData 5.5. Then again using the NuGet package manager, reinstall Microsoft.WindowsAzure.Storage which identified that it needed Microsoft.Data.OData 5.2 and installed that too.

所以解决方案是使用 NuGet 包管理器卸载 Microsoft.WindowsAzure.Storage,这反过来卸载了 Microsoft.Data.OData 5.5。然后再次使用 NuGet 包管理器,重新安装 Microsoft.WindowsAzure.Storage,它确定它需要 Microsoft.Data.OData 5.2 并安装它。

and back to a working solution.

并回到一个有效的解决方案。

回答by eesh

You can solve this issue in general whenever you update packages or add new packages via NuGet and end up with "Could Not Load file or Assembly..." issues.

每当您通过 NuGet 更新包或添加新包并最终出现“无法加载文件或程序集...”问题时,通常都可以解决此问题。

Open the Package Manager Console(VS 2012 Tools/Library Package Manager/ Package Manager Console). Once the shell opens for the Package Manager Console run the command:

打开包管理器控制台VS 2012 工具/库包管理器/包管理器控制台)。为包管理器控制台打开外壳后,运行命令:

Add-BindingRedirect

添加绑定重定向

Note: Be careful as the NugGet example added an 's' to the end in their example and Add-BindingRedirectis not a valid command.

注意:注意 NugGet 示例在其示例的末尾添加了一个 's' 并且Add-BindingRedirect不是有效命令。

This does the following:

这将执行以下操作:

Examines all assemblies in the output path for a project and adds binding redirects to the application configuration (app.config) file or to the web configuration (web.config) file where required.

检查项目输出路径中的所有程序集,并在需要时将绑定重定向添加到应用程序配置 (app.config) 文件或 Web 配置 (web.config) 文件。

You can see complete documentation for the Package Manager Console at: http://nuget.codeplex.com/wikipage?title=Package%20Manager%20Console%20Command%20Reference%20(v1.3)

您可以在以下位置查看包管理器控制台的完整文档:http: //nuget.codeplex.com/wikipage?title=Package% 20Manager%20Console%20Command%20Reference%20(v1.3)

In addition to the two entries you see in astaykov's answer the following was also added for my Project.

除了您在 astaykov 的回答中看到的两个条目之外,还为我的项目添加了以下内容。

  <dependentAssembly>
    <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
  </dependentAssembly>

回答by Szymon Drosdzol

I had similar problem today. The only difference I spotted is my cloud app was looking (and failing to find) for Microsoft.Data.OData in Version=5.2.0.0

我今天遇到了类似的问题。我发现的唯一区别是我的云应用程序正在寻找(但未能找到)版本 = 5.2.0.0 的Microsoft.Data.OData

Using Visual Studio Object Browser i found out that my solution used library from that location:

使用 Visual Studio 对象浏览器,我发现我的解决方案使用了该位置的库:

C:\Program Files (x86)\Microsoft WCF Data Services\5.0\bin\.NETFramework

C:\Program Files (x86)\Microsoft WCF Data Services\5.0\bin\.NETFramework

Microsoft.Data.OData library residing there was in ver. 5.0.0.0so overwriting it with 5.2.0.0resolved the problem.

驻留在那里的 Microsoft.Data.OData 库在版本中。5.0.0.0所以用5.2.0.0覆盖它解决了这个问题。

P.S. I installed WCF Data Services Tools for Windows Store Apps earlier in hope of resolving this issue so it may happen that your application gets it from another source. If that is the case you have two options:

PS 我之前为 Windows 应用商店应用程序安装了 WCF 数据服务工具,希望能解决这个问题,因此您的应用程序可能会从其他来源获取它。如果是这种情况,您有两种选择:

  1. Install WCF Data Services Tools for Windows Store Apps from hereand use solution above.

  2. Use Visual Studio Object Browser to find what versions of OData library are currently visible for your project and where they are stored. Next you need to overwrite improper versions of them.

  1. 此处安装适用于 Windows 应用商店应用程序的 WCF 数据服务工具并使用上述解决方案。

  2. 使用 Visual Studio 对象浏览器查找当前对您的项目可见的 OData 库版本以及它们的存储位置。接下来,您需要覆盖它们的不正确版本。

回答by Scott Stafford

I had a similar problem as well, but I wasn't using Azure and there was no hard-coded reference that was pointing to 5.2. But it resolved (after finding this article) by making sure that the text in the .svc pointed to the correct assembly:

我也有类似的问题,但我没有使用 Azure,也没有指向 5.2 的硬编码引用。但是它通过确保 .svc 中的文本指向正确的程序集来解决(在找到这篇文章之后):

<%@ ServiceHost Language="C#"
      Factory="System.Data.Services.DataServiceHostFactory,
      Microsoft.Data.Services, Version=5.6.0.0,
      Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Service="MVC4WCFDataServiceFE5.NorthWindService" %>

服务="MVC4WCFDataServiceFE5.NorthWindService" %>

Note the Version=5.6.0.0, which I didn't have before.

注意Version=5.6.0.0,我以前没有。