Dot-Net

為什麼 AutoMapper v3 不能工作,因為它正在尋找 v2.2.1.0?

  • January 26, 2015

我剛剛通過 nuGet 在一個新項目上安裝了 AutoMapper,但是當我執行程式碼時,出現以下錯誤:

無法載入文件或程序集“AutoMapper,Version=2.2.1.0,Culture=neutral,PublicKeyToken=be96cd2c38ef1005”或其依賴項之一。找到的程序集的清單定義與程序集引用不匹配。(來自 HRESULT 的異常:0x80131040)

為什麼它在尋找 Version=2.2.1.0,我該怎麼辦?恢復到那個版本?

您可能只想為 AutoMapper 添加綁定重定向,因為您的參考之一正在尋找 2.2 版

這應該這樣做:

<dependentAssembly>
     <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" 
                    culture="neutral"/>
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
   </dependentAssembly>

再次嘗試解除安裝並重新安裝 AutoMapper。

如果您的解決方案中有多個項目,那麼您的一個項目中可能已經安裝了 2.2.1.0 版本。但是 AutoMapper 的最新版本是 3.0.0,所以這就是你遇到問題的原因。

引用自:https://stackoverflow.com/questions/18552159