【问题标题】:Azure Diagnostics is looking for StorageClient 1.7.0.0, but I'm using StorageClient 1.7.1.0Azure 诊断正在寻找 StorageClient 1.7.0.0,但我使用的是 StorageClient 1.7.1.0
【发布时间】:2023-03-10 05:53:01
【问题描述】:

我正在使用 Microsoft.WindowsAzure.StorageClient 版本 1.7.1.0,可在以下网址获得:https://github.com/WindowsAzure/azure-sdk-for-net/tree/sdk_1.7.1。我的项目编译得很好,但是当我运行它时出现以下错误:

Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

内部例外:

Could not load file or assembly 'Microsoft.WindowsAzure.StorageClient, Version=1.7.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.WindowsAzure.StorageClient, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

我看起来 Microsoft.WindowsAzure.Diagnostics 中的 Microsoft.WindowsAzure.StorageClient 版本 1.7.0.0 存在依赖关系。但是我使用的是 1.7.1.0 版本,据我所知,我不能在同一个项目中同时拥有 1.7.0 和 1.7.1。如果这确实是问题,任何想法如何使 Microsoft.WindowsAzure.Diagnostics 依赖于 1.7.1?

谢谢,库尔特


更新


根据下面的建议,我添加了启动任务以使用 gacutil 加载 1.7.0 版本(这很有用 http://blogs.infosupport.com/adding-assemblies-to-the-gac-in-windows-azure/)。我有 2 个 WorkerRoles 和 2 个 WebRoles。我现在遇到的问题是,当我编译和运行时,VS2012 将 1.7.0 复制到 WebRoles 各自的 ...\csx\Debug\roles[WebRoleName]\approot 文件夹中,尽管没有直接引用 1.7 版。项目中为 0。以下编译输出显示了当 Azure 尝试加载版本 1.7.1(现在找不到)时引入的错误:

System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.StorageClient, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.WindowsAzure.StorageClient, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null'

=== Pre-bind state information ===
LOG: User = BERTIES_MAIN\kurt_000
LOG: DisplayName = Microsoft.WindowsAzure.StorageClient, Version=1.7.1.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///H:/Everything/Current_Work/Web_Apps/Azure/InSysCloud/InSysCloud/InSysCloud/csx/Debug/roles/InSysWatcher/approot
LOG: Initial PrivatePath = H:\Everything\Current_Work\Web_Apps\Azure\InSysCloud\InSysCloud\InSysCloud\csx\Debug\roles\InSysWatcher\approot
Calling assembly : InSysWatcher, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: H:\Everything\Current_Work\Web_Apps\Azure\InSysCloud\InSysCloud\InSysCloud\csx\Debug\roles\InSysWatcher\approot\InSysWatcher.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///H:/Everything/Current_Work/Web_Apps/Azure/InSysCloud/InSysCloud/InSysCloud/csx/Debug/roles/InSysWatcher/approot/Microsoft.WindowsAzure.StorageClient.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

为什么 VS2012 会为 1.7.0 版本添加 DLL,而 1.7.1 版本在项目本身中被引用,而 1.7.0 版本仅作为内容包含,并在应用启动时加载到 GAC 中?

【问题讨论】:

  • 您的版本中有什么特别需要的吗?老实说,我现在可能只是回到 1.7.0 正式版。在第 3 方尝试加载存储客户端(例如诊断代理)的任何地方,您都会遇到此问题。
  • 我打算为表和队列使用共享访问密钥功能,我认为 1.7.0 不支持该功能。我假设(并且真的希望)1.7.1 中的这个功能将进入官方 1.8。

标签: azure storage diagnostics


【解决方案1】:

好吧,在这种情况下,您将在 web.config/app.config 中使用绑定重定向。但问题是PublicKeyToken。 “官方”程序集 1.7.0.0 具有以下 PublicKeyToken:31bf3856ad364e35

现在,由于您自己构建 1.7.1.0 版本,您最终会得到不同的 PublicKeyToken,在这种情况下绑定重定向不起作用。

但是 GAC 就是为此而构建的,以支持程序集的多个版本。我的建议如下:

  1. 在您的包中包含 1.7.0.0 程序集,但将其添加为内容(而不是作为参考)。
  2. 创建一个启动任务,将程序集部署到 GAC(使用 gacutil),因为任务 will run before starting 您的角色。
  3. 继续使用带有普通程序集引用的 1.7.1.0。
  4. 您的应用应为您的代码使用 1.7.1.0,诊断程序集应能够使用 GAC 的 1.7.0.0 版本

我还没有机会对此进行测试,所以我正在期待您的反馈。

【讨论】:

  • OK - 这看起来很有希望。我添加了启动任务有一点点皱纹 - 我必须更改程序集的 1.7.0 文件名,否则当我尝试添加 1.7.1 版本时,Visual Studio 将引用 1.7.0,无论我尝试添加哪个版本直接参考。无论如何,现在我有一个问题,当我尝试构建我的解决方案时,仅针对 WorkerRoles,VS2012 将版本 1.7.0(不是 1.7.1)放入 csx/Debug/roles/WorkerRoleName/approot 文件夹中,尽管没有直接在我的项目中引用它。对于 WebRoles,将复制正确的版本 (1.7.1)。有什么想法吗?
  • 我可以强制我编译的 1.7.1 的 PublicKeyToken 为 31bf3856ad364e35 吗?
  • 我实际上试图通过使用 ILDASM 将 1.7.0 的相关部分剪切并粘贴到 1.7.1 中来更改 PublicKeyToken,但后来意识到我无权访问 Microsoft 的私钥 :-(这意味着我必须为生成的 1.7.1 关闭强名称验证,然后导致 GetObjectData 方法出现安全问题......关于“覆盖成员时违反继承安全规则......”的一些事情
  • 我还尝试使用 Microsoft.WindowsAzure.StorageClient2 的程序集名称重命名和重新编译 Microsoft.WindowsAzure.StorageClient 的 1.7.1 版
  • 顺便说一句,这不应该被标记为答案,因为它对我不起作用。我没有足够的声望点来投反对票。
【解决方案2】:

看来我可以在我的 web.config 中添加以下参考来解决这个问题:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.StorageClient"
                          publicKeyToken="31bf3856ad364e35"
                          culture="neutral" />
        <bindingRedirect oldVersion="1.1.0.0"
                         newVersion="1.7.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.StorageClient"
                          publicKeyToken="31bf3856ad364e35"
                          culture="neutral" />
        <publisherPolicy apply="no" />
      </dependentAssembly>

    </assemblyBinding>
  </runtime>

这实质上允许对 dll 的 v1.1 的引用重新映射到 1.7。

【讨论】:

    猜你喜欢
    • 2012-03-25
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    相关资源
    最近更新 更多