AssemblyBinding BindingRedirect不工作与T4MVCExtensions MVC4应用 [英] AssemblyBinding BindingRedirect not working for MVC4 app with T4MVCExtensions

查看:566
本文介绍了AssemblyBinding BindingRedirect不工作与T4MVCExtensions MVC4应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个是MVC3,使用T4MVC大量.NET Web应用程序。我们最近升级为MVC4,一切都只是T4MVCExtensions(版本3.6.5自的NuGet)好还是依赖System.Web.Mvc版本3.你应该设置在web.config中运行时依赖SHOULD是重定向组件绑定,但他们似乎并不如此。出现以下异常:

We have a large .NET web application that was MVC3, using T4MVC. We recently upgraded it to MVC4, and all is good except for T4MVCExtensions (version 3.6.5 from NuGet) is still dependent on System.Web.Mvc version 3. The runtime dependencies that you're supposed to setup in the web.config SHOULD be redirecting the assembly bindings, but they don't seem to be. The following exception occurs:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Description: An unhandled exception occurred during the execution of the current web     request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

我们已经得到了我们的web.config文件中,应绘制了以下,但它似乎并没有被 -

We've got the following in our web.config file, which should be mapping it, but it doesn't seem to be -

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers"
                      publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc"
                      publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages"
                      publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

我已经启用了日志的融合,只是要真正验证我的疯狂,而看到的是,确实是,它似乎是试图使用MVC3二进制,并且不打算4:

I've enabled the fusion log, just to verify my craziness really, and see that, yes indeed, it does seem to be trying to use the mvc3 binary, and not going to 4:

*** Assembly Binder Log Entry  (5/21/2013 @ 3:37:23 PM) ***

The operation failed.
Bind result: hr = 0x80004005. Unspecified error

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = IIS APPPOOL\ASP.NET v4.0
LOG: DisplayName = System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Work/Webs/SSUApp/SSUApp/
LOG: Initial PrivatePath = C:\Work\Webs\SSUApp\SSUApp\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lssapp\7a6e6cde
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\lssapp\7a6e6cde
LOG: AppName = d5bcf9a8
Calling assembly : App_Web__managerulespartial.cshtml.38bccb18.jb5ozz39, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Start validating all the dependencies.
LOG: [Level 1]Start validating native image dependency mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating IL dependency System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: [Level 1]Start validating native image dependency System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating native image dependency System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating IL dependency System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
LOG: [Level 1]Start validating IL dependency Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: [Level 1]Start validating IL dependency System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating IL dependency System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
LOG: [Level 1]Start validating IL dependency System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
Native image has correct version information.
LOG: Validation of dependencies succeeded.
LOG: Bind to native image succeeded.
Attempting to use native image C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Web.Mvc\f234ba2bcf5f845279e46dc04198a7cd\System.Web.Mvc.ni.dll.
Rejecting code sharing because a dependent assembly did not match the conditional APTCA share mode
Native image successfully used.

任何想法就会动摇,因为我已经烧了一堆小时这一点。

Any ideas would rock, since I've already burned a bunch of hours on this.

谢谢,
弗朗西斯

Thanks, Francis

推荐答案

我有一个非常类似的程序集绑定的问题,后手动升级一套MVC3项目MVC4的。尽管有装配在web.config中绑定元素,我是越来越相似T4MVC错误,但是从Telerik的MVC扩展的错误。

I had a very similar assembly binding issue, after manually upgrading a set of MVC3 projects to MVC4. Despite having the assembly binding elements in web.config, I was getting errors similar to T4MVC errors but from the Telerik MVC Extensions.

,因为它证实了system.web.mvc的两个版本都被加载到应用程序域融合日志查看器是有益的。

The Fusion Log viewer was useful as it confirmed that two versions of system.web.mvc were being loaded into the application domain.

在年底,在项目的根web.config根配置元素删除命名空间解决了这个问题。

In the end, removing the namespace from the root configuration element in the project's root web.config resolved the issue.

所以,在web.config是这样的:

So, the web.config was like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<!--... elements deleted for clarity ...-->
</configuration>

和拆卸后的命名空间,它看起来是这样的:

And after removing the namespace it looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--... elements deleted for clarity ...-->
</configuration>

本博客帖子大约有错误的命名空间的更多信息:
<一href=\"http://www.dotnetish.com/runtime/xmlnshttpschemas-microsoft-com-netconfigurationv2-0/\">http://www.dotnetish.com/runtime/xmlnshttpschemas-microsoft-com-netconfigurationv2-0/

This blog post has more information about the erroneous namespace: http://www.dotnetish.com/runtime/xmlnshttpschemas-microsoft-com-netconfigurationv2-0/

这篇关于AssemblyBinding BindingRedirect不工作与T4MVCExtensions MVC4应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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