2013-05-21 17 views
5

Chúng tôi có một ứng dụng web .NET lớn là MVC3, sử dụng T4MVC. Gần đây chúng tôi đã nâng cấp nó lên MVC4 và tất cả đều tốt ngoại trừ T4MVCExtensions (phiên bản 3.6.5 từ NuGet) vẫn còn phụ thuộc vào phiên bản System.Web.Mvc 3. Các phụ thuộc thời gian chạy mà bạn phải thiết lập trong web.config NÊN NÊN được chuyển hướng các ràng buộc lắp ráp, nhưng họ dường như không được. Trường hợp ngoại lệ sau đây xảy ra:AssemblyBinding BindingRedirect không hoạt động đối với ứng dụng MVC4 với T4MVCExtensions

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 

Chúng tôi đã có những điều sau đây trong tập tin web.config của chúng tôi, mà phải được lập bản đồ nó, nhưng nó dường như không thể -

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

Tôi đã bật nhật ký tổng hợp, chỉ để xác minh sự điên rồ của mình và thấy rằng, có thực sự, có vẻ như đang cố gắng sử dụng nhị phân mvc3 và không phải 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. 

Bất kỳ ý tưởng nào đều có thể xảy ra, vì tôi đã đốt cháy hàng giờ đồng hồ về điều này.

Cảm ơn, Francis

Trả lời

11

Tôi đã có một vấn đề ràng buộc lắp ráp rất giống nhau, sau khi nâng cấp thủ công một tập hợp các dự án MVC3 lên MVC4. Mặc dù có các yếu tố ràng buộc lắp ráp trong web.config, tôi đã nhận được lỗi tương tự như lỗi T4MVC nhưng từ phần mở rộng Telerik MVC.

Trình xem Nhật ký kết hợp hữu ích khi xác nhận rằng hai phiên bản system.web.mvc đã được tải vào miền ứng dụng.

Cuối cùng, việc xóa không gian tên khỏi phần tử cấu hình gốc trong web.config gốc của dự án đã giải quyết được sự cố.

Vì vậy, web.config đã như thế này:

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

Và sau khi loại bỏ các không gian tên nó trông như thế này:

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

bài viết trên blog này có thêm thông tin về không gian tên có sai sót: http://www.dotnetish.com/runtime/xmlnshttpschemas-microsoft-com-netconfigurationv2-0/

+1

Bạn thưa ngài, hãy chiến thắng! Đó là chính xác những gì nó được. Cảm ơn bạn rất nhiều. –

0

Để cô lập, tôi sẽ cố gắng tạo ra một assembly giả nhỏ xíu mà được xây dựng chống MVC3 để xem nếu nó cư xử tương tự. Không nên có bất cứ điều gì đặc biệt về hội đồng trợ giúp T4MVC.

Ngoài ra, hãy xem dự án thử nghiệm của tôi https://github.com/davidebbo/T4MVCSampleApp. Đây là một dự án MVC4 sử dụng T4MVC mới nhất, và nó chạy tốt cho tôi. Nó có chạy cho bạn không?

Nếu mọi thứ khác không thành công, nếu bạn có thể chia sẻ dự án repro (ví dụ: trên github), tôi có thể thử xem.

+0

Cảm ơn bạn đã phản hồi David, tôi đã thử cách ly, và tất nhiên nó đã hoạt động hoàn hảo. Trong thực tế, tôi thậm chí đã bắt đầu một dự án ứng dụng web mới trong giải pháp của tôi và nó cũng đang hoàn thiện. Kể từ khi tôi nộp lỗi, tôi cũng đã có cùng một vấn đề với một WebGrease.dll cập nhật, vì vậy tôi nghĩ rằng T4MVCExtension là hoàn toàn vô tội trong trường hợp này, tôi chắc chắn nó chỉ là một cấu hình sai trong web.config của dự án của tôi. BTW - Tôi yêu T4MVC, đó là một sự bổ sung tuyệt vời cho khung công tác và thực sự đoán được việc sử dụng MVC. Cám ơn rất nhiều. –

+0

Chỉ cần xem giải pháp ở trên. Rất vui khi làm việc! –

Các vấn đề liên quan