今天發布web API,調用接口報錯了:未能加載文件或程序集“System.Web.Http, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一個依賴項。找到的程序集清單定義與程序集引用不匹配。 (異常來自 HRESULT:0x80131040)
代碼沒問題,找了一會,發現是Web.Config的問題。runtime缺少dependentAssembly。加上就好了~
<dependentAssembly> <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" /> </dependentAssembly>
復盤:
- 發布沒有更新Web.Config,報錯需要比對一下Web.Config。
- 如果返回內部錯誤,可以加上<customErrors mode="Off"/>,查看具體的錯誤信息。
<system.web> <customErrors mode="Off"/> </system.web>