程序集绑定重定向不起作用 [英] Assembly binding redirect not working

查看:27
本文介绍了程序集绑定重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Azure 上部署测试 Web 应用程序,但是当我在本地计算机上运行 Azure 模拟器时,我从附加到我的 WebRole 的 Azure 模拟器控制台收到此错误:

I am trying to deploy a test web app on Azure, but when I run the Azure emulator on my local machine I get this error from the Azure emulator console attached to my WebRole:

System.TypeLoadException: Unable to load the role entry point due to the following     exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.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)
File name: 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

=== Pre-bind state information ===
LOG: User = COLLABmirko.lugano
LOG: DisplayName = System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Code/Application/<MyWebProject>.Azure/csx/Debug/roles/<MyWebProject>/approot/bin
LOG: Initial PrivatePath = C:CodeApplication<MyWebProject>.AzurecsxDebug
oles<MyWebProject>approotin
Calling assembly : ActionMailer.Net.Mvc, Version=0.7.4.0, Culture=neutral, PublicKeyToken=e62db3114c02a1c2.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:CodeApplication<MyWebProject>.AzurecsxDebug
oles<MyWebProject>asex64WaIISHost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config.
LOG: Post-policy reference: System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Code/Application/<MyWebProject>.Azure/csx/Debug/roles/<MyWebProject>/approot/bin/System.Web.Mvc.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
  at System.Reflection.RuntimeModule.GetTypes()
  at System.Reflection.Assembly.GetTypes()
  at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
  --- End of inner exception stack trace ---
  at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
  at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(RoleType roleTypeEnum)
  at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
[fabric] Role state Unknown

只要我在本地机器上安装了 MVC3(MVC3 程序集在 GAC 中),一切都运行良好,但是由于我删除了 MVC3(Azure 没有安装 MVC),我收到了这个错误.我的 Web 应用程序定期包含 MVC4,并且运行良好.然后我想到了程序集绑定重定向,我注意到在我的 web.config 文件中我已经有了:

Everything had been working fine as long as I had MVC3 installed on my local machine (the MVC3 assembly was in GAC), but since I removed MVC3 (Azure has no MVC installed), I am getting this error. My web app has MVC4 regularly included and that works fine. I had then thought about assembly binding redirection, and I noticed that in my web.config file I already have:

  <runtime>    
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      
    ...
    <dependentAssembly>        
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    ...
  </assemblyBinding>
</runtime>

根据我在互联网上阅读的文档,这应该已经正确了.我还尝试将我的 System.Web.Mvc.dll(版本 4.0.0.0)的 SpecificVersion 属性设置为 false 但无济于事.我错过了什么吗?调用程序集 ActionMailer.Net.Mvc 不应该自动重定向到正确版本的 MVC 程序集吗?任何想法都非常感谢.谢谢.

which should be already correct, according to the documentation I have read around in internet. I have also tried setting the SpecificVersion property of my System.Web.Mvc.dll (version 4.0.0.0) to false but to no avail. Am I missing something? Shouldn't the calling assembly ActionMailer.Net.Mvc be automatically redirected to the correct version of the MVC assembly? Any ideas are greatly appreciated. Thanks.

推荐答案

在 Azure WebRoles 中,默认情况下(在完整 IIS 模式下)RoleEntryPoint 与 WebRole 的其余部分隔离,并在不同的进程中运行.

In Azure WebRoles, by default (in Full IIS Mode) the RoleEntryPoint gets walled off from the rest of the WebRole, and runs in a different process.

这样做的副作用是您的 RoleEntryPoint 将无法访问您的 web.config.

A side effect of this is that your RoleEntryPoint will not have access to your web.config.

  • Azure SDK 1.3 -1.7 将在 WaIISHost.exe.config

Azure SDK 1.8+ 将查看 WebRoleProjectName.dll.config.

Azure SDK 1.8+ will look in the WebRoleProjectName.dll.config.

随着对 SDK 的最新更改,您应该能够在您的项目中放置一个 app.config,然后您的角色入口点应该可以访问它.

With the newest change to the SDK, you should be able to place an app.config in your project and your role entry point should then have access to it.

您可以在此 Microsoft 博客文章 或在此Stackoverflow 文章>

You can read more about this in this Microsoft blog post or in this Stackoverflow post

这篇关于程序集绑定重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆