asp.net-mvc – 汇编绑定重定向不工作

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 汇编绑定重定向不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在Azure上部署一个测试Web应用程序,但是当我在本地机器上运行Azure模拟器时,我会从附加到我的WebRole的Azure模拟器控制台得到这个错误
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,PublicKeyToken=31bf3856ad364e35'

=== Pre-bind state information ===
LOG: User = COLLAB\mirko.lugano
LOG: DisplayName = System.Web.Mvc,PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Code/Application/<MyWebProject>.Azure/csx/Debug/roles/<MyWebProject>/approot/bin
LOG: Initial PrivatePath = C:\Code\Application\<MyWebProject>.Azure\csx\Debug\roles\<MyWebProject>\approot\bin
Calling assembly : ActionMailer.Net.Mvc,Version=0.7.4.0,PublicKeyToken=e62db3114c02a1c2.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\Application\<MyWebProject>.Azure\csx\Debug\roles\<MyWebProject>\base\x64\WaIISHost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Mvc,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),所以一直工作正常,我收到这个错误.我的网络应用程序经常包含MVC4,工作正常.我曾经想过装配绑定重定向,我注意到在我的web.config文件中我已经有:

<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程序集?任何想法都非常感激.谢谢.

解决方法

在Azure WebRoles中,默认情况下(在完全IIS模式下),RoleEntryPoint将与WebRole的其余部分保持一致,并运行在不同的进程中.

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

> Azure SDK 1.3 -1.7将查看WaIISHost.exe.config
> Azure SDK 1.8将查看WebRoleProjectName.dll.config.

随着SDK的最新更改,您应该可以在应用程序中放置一个app.config,然后角色入口点就可以访问它.

您可以在此Microsoft blog postStackoverflow post中阅读有关此更多信息

猜你在找的asp.Net相关文章