2013-05-21 51 views
5

我們有一個使用T4MVC的大型.NET Web應用程序,它是MVC3。我們最近將它升級到了MVC4,並且除了T4MVCExtensions(來自NuGet的3.6.5版本)仍然依賴於System.Web.Mvc版本3以外,它們都很好。您應該在web.config中設置的運行時依賴關係應該重新定向程序集綁定,但它們似乎不是。出現以下異常:AssemblyBinding BindingRedirect不適用於使用T4MVCExtensions的MVC4應用程序

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. 

任何想法都會搖擺不定,因爲我已經在這上面燒了一大堆小時。

感謝, 弗朗西斯

回答

11

手動將一組MVC3項目升級到MVC4後,我有一個非常類似的程序集綁定問題。儘管在web.config中有組件綁定元素,但我得到的錯誤類似於T4MVC錯誤,但來自Telerik MVC Extensions。

Fusion日誌查看器很有用,因爲它確認兩個版本的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/

+1

你先生,贏了!這正是它的原因。非常感謝。 –

0

隔離開來,我會嘗試創建是建立針對MVC3,看它是否同樣表現一個微小的仿製組件。 T4MVC輔助組件不應有任何特殊之處。

另外,請看我的測試項目https://github.com/davidebbo/T4MVCSampleApp。這是一個使用最新T4MVC的MVC4項目,它對我來說運行良好。它會爲你運行嗎?

如果一切都失敗了,如果你可以共享一個repro項目(例如在github上),我可以試着看看。

+0

謝謝你的迴應大衛,我試過隔離,當然它的工作完美。事實上,我甚至已經在我的解決方案中開始了一個新的Web應用程序項目,並且它也完全重新綁定。由於我提交了bug,我也遇到了與更新的WebGrease.dll相同的問題,所以我認爲T4MVCExtension在這種情況下是完全無辜的,我相信這只是我項目web.config中的錯誤配置。 順便說一句 - 我喜歡T4MVC,這是一個非常棒的除了框架,並真正採用MVC的猜測工作。非常感謝。 –

+0

剛剛看到上面的解決方案。很高興工作! –

相關問題