0

我正在使用 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 中?

4

2 回答 2

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),因为该任务将在开始您的角色之前运行。
  3. 继续使用 1.7.1.0 和正常的程序集参考。
  4. 您的应用程序应为您的代码使用 1.7.1.0,并且诊断程序集应该能够使用 GAC 的 1.7.0.0 版本

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

于 2012-10-11T08:59:33.623 回答
0

看来我可以在我的 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。

于 2013-07-01T13:18:32.793 回答