gpt4 book ai didi

c# - AssemblyBinding BindingRedirect 不适用于带有 T4MVCExtensions 的 MVC4 应用程序

转载 作者:太空狗 更新时间:2023-10-29 22:22:57 28 4
gpt4 key购买 nike

我们有一个大型 .NET Web 应用程序,它是 MVC3,使用 T4MVC。我们最近将它升级到 MVC4,除了 T4MVCExtensions(来自 NuGet 的 3.6.5 版)仍然依赖于 System.Web.Mvc 版本 3 之外,一切都很好。您应该在 web.config 中设置的运行时依赖项应该正在重定向程序集绑定(bind),但它们似乎不是。出现以下异常:

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 文件中有以下内容,应该是映射它,但它似乎不是 -

<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:

*** 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.

任何想法都会动摇,因为我已经为此花费了大量时间。

谢谢,弗朗西斯

最佳答案

在将一组 MVC3 项目手动升级到 MVC4 之后,我遇到了一个非常相似的程序集绑定(bind)问题。尽管在 web.config 中有程序集绑定(bind)元素,但我收到了类似于 T4MVC 错误的错误,但是来自 Telerik MVC 扩展。

Fusion Log 查看器很有用,因为它确认两个版本的 system.web.mvc 被加载到应用程序域中。

最后,从项目的根 web.config 中的根配置元素中删除命名空间解决了这个问题。

所以,web.config 是这样的:

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

删除命名空间后,它看起来像这样:

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

这篇博文包含有关错误命名空间的更多信息: http://www.dotnetish.com/runtime/xmlnshttpschemas-microsoft-com-netconfigurationv2-0/

关于c# - AssemblyBinding BindingRedirect 不适用于带有 T4MVCExtensions 的 MVC4 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16678395/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com