我正在使用:https://github.com/WindowsAzure/azure-sdk-for-net/tree/sdk_1.7.1提供的Microsoft.WindowsAzure.StorageClient版本1.7.1.0。我的项目编译得很好,但是当我运行它时出现以下错误:
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.StorageClient版本1.7.0.0上的Microsoft.WindowsAzure.Diagnostics中存在依赖关系。但是我使用的是1.7.1.0版本,据我所知,我不能在同一个项目中同时拥有1.7.0和1.7.1。如果这确实是问题,如何使Microsoft.WindowsAzure.Diagnostics依赖于1.7.1的任何想法?
谢谢Kurt
更新
根据下面的建议,我添加了启动任务,使用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尝试加载verison 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中?
答案 0 :(得分:1)
嗯,在这种情况下,您将在web.config / app.config中使用绑定重定向。但问题是PublicKeyToken。 '官方'程序集1.7.0.0具有以下PublicKeyToken: 31bf3856ad364e35 。
现在,由于您自己构建1.7.1.0版本,因此最终会使用不同的PublicKeyToken,在这种情况下,绑定重定向不起作用。
但GAC是为此而构建的,以支持多个版本的程序集。我建议如下:
我没有机会对此进行测试,所以我正在寻找您的反馈意见。
答案 1 :(得分: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。