2017-11-04 375 views
1

我正嘗試使用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

ILSpy inspection into Microsoft.Rest.ClientRuntime

我也曾嘗試刪除所有引用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) 

我錯過了什麼?

+0

你能解決這個問題嗎?我現在有同樣的問題,我已經嘗試了很多我在網上找到的潛在解決方案,但似乎沒有任何工作... –

+1

沒有,但我使用了實體框架附帶的migrate.exe,並且解除了阻止部署對數據庫的更改。我認爲visual studio仍然被封鎖(即包管理器控制檯),但我根本不在乎。 – lbartnik

回答

1

發現注:Kunal的回答以後這裏:

MongoDB client throws a FileNotFoundException in mscorlib

工作對我來說,我試圖改變爲System.Net.Http版本號。我有System.Net.Http版本4.3.3安裝目標net462和這工作對我來說:

<dependentAssembly> 
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> 
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/> 
</dependentAssembly>