2012-09-07 91 views
1

我正在創建一個新的MVC 4網站,並且我想使用Unity.MVC3庫來整合MVC中內置的DependencyResolver內容。Unity的綁定重定向不起作用

我也想引用一些舊的,更大的項目的一些數據訪問DLL。

我的問題是,Unity.MVC3和較舊的DLL分別針對不同版本的Unity,1.2.0.0和2.1.505.0進行編譯。我想在我的web.config文件中創建一個綁定重定向,像這樣:

<dependentAssembly> 
    <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersions="1.2.0.0-2.1.505.0" newVersion="2.1.505.0" /> 
    </dependentAssembly> 

不過,我還是得到了以下錯誤:

Could not load file or assembly 'Microsoft.Practices.Unity, Version=1.2.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) 

我打開集綁定日誌記錄,最後兩行狀態:

WRN: Comparing the assembly name resulted in the mismatch: Major Version 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

爲什麼我的綁定重定向不被尊重?有沒有辦法來覆蓋其檢查主要版本衝突?

+0

您能否在融合日誌中看到綁定重定向是否實際上被使用? – fsimonazzi

回答

2

有一個在關鍵令牌一個錯字:

<assemblyIdentity name="Microsoft.Practices.Unity" 
    publicKeyToken="31bf856ad364e35" /> 

應該是:

<assemblyIdentity name="Microsoft.Practices.Unity" 
    publicKeyToken="31bf3856ad364e35" /> 

綁定重定向does not complain in case of typos,它只是什麼都不做。

我做了一個測試程序,這個配置它的工作原理:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.2.0.0" newVersion="2.1.505.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

注重xmlns,沒有它,它靜靜地失敗。

+0

好抓!但似乎並沒有解決這個問題。仍然收到錯誤。 –

+0

好吧,我試過了。答案已更新 – onof