我正嘗試使用NuGet程序包管理器控制檯將更改部署到數據庫。當我發出命令Update-Database
,它失敗並顯示錯誤消息說:.NET中的庫版本衝突:System.Net.Http
Could not load file or assembly 'System.Net.Http, Version=4.1.1.1,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
我的項目面向.NET 4.5.2其中,據我所知,在4.0.0.0
版本提供System.Net.Http
。因此,被控制的庫不在二進制輸出目錄中。當我下載4.1.1.1
版本(NuGet包4.3.2版本),並將其複製到二進制輸出目錄,用我的DLL以來,我收到其他錯誤消息:
Loading this assembly would produce a different grant set from other
instances. (Exception from HRESULT: 0x80131401)
在這兩種情況下的例外是System.IO.FileLoadException
,它被投入Microsoft.Rest.ServiceClient'1.CreateRootHandler()
。我檢查了功能其實引用.NET 4.5和System.Net.Http
的源代碼和它:
protected static HttpClientHandler CreateRootHandler()
{
// Create our root handler
#if NET45
return new WebRequestHandler();
#else
return new HttpClientHandler();
#endif
}
然而,無處我能找到的System.Net.Http
確切的版本號。最後,我用ILSpy檢查Microsoft.Rest.ClientRuntime
,它似乎取決於版本4.0.0.0
中的System.Net.Http
。
我也曾嘗試刪除所有引用System.Net.Http
和安裝最新的NuGet(4.3.2)。導致後續錯誤缺少方法:
Method not found: 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(
AuthenticationCallback, System.Net.Http.DelegatingHandler[])'.
和
Method not found: 'Void Microsoft.Rest.ServiceClient`1..ctor(
System.Net.Http.DelegatingHandler[])'.
我通過複製從各自的NuGet權DLL到部署目錄解決。這終於回到:
Loading this assembly would produce a different grant set from other
instances. (Exception from HRESULT: 0x80131401)
我錯過了什麼?
你能解決這個問題嗎?我現在有同樣的問題,我已經嘗試了很多我在網上找到的潛在解決方案,但似乎沒有任何工作... –
沒有,但我使用了實體框架附帶的migrate.exe,並且解除了阻止部署對數據庫的更改。我認爲visual studio仍然被封鎖(即包管理器控制檯),但我根本不在乎。 – lbartnik