簡體   English   中英

無法加載文件或程序集或其依賴項之一。

[英]Could not load file or assembly or one of its dependencies.

我知道這個問題很多,但是我嘗試了所有解決方案,但沒有成功!

在調試模式下運行時,這是錯誤:

System.IO.FileLoadException:'無法加載文件或程序集'System.Runtime.InteropServices.RuntimeInformation,版本= 4.0.0.0,區域性=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依賴項之一。 找到的程序集的清單定義與程序集引用不匹配。 (來自HRESULT的異常:0x80131040)

我嘗試刪除solution所有projects所有binobj文件夾。 還刪除了Packages文件夾。

還刪除了所有配置文件中的此項:

<dependentAssembly>
    <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>

還在上面的代碼newVersion值更改為4.0.0.0但絕不喜歡!

當我卸載項目並對其進行編輯時,我看到以下行:

<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>

我怎么解決這個問題? 提前致謝。

可能為時已晚,但是在使用.net 4.6.2的一台舊版構建服務器上,MongoDB驅動程序(從2.5升級到2.7)遇到了類似的問題。 奇怪的是,使用Visual Studio構建時,它可以在本地計算機上工作。 問題在於NuGet本身,以及在軟件包更新期間添加的錯誤程序集綁定。 我們必須手動檢查正確的程序集版本並覆蓋app.config中的值。

確保通過在目標計算機上添加以下注冊表項來激活詳細的日志記錄:HKLM \\ Software \\ Microsoft \\ Fusion> EnableLog(DWORD)設置為1

然后,您可以獲得更詳細的信息,確切的DLL會引起問題。

以下PowerShell命令可以幫助找到正確的程序集版本。 例如,InteropServices:

[System.Reflection.Assembly]::LoadFrom("C:\path_to_your_release_folder\System.Runtime.InteropServices.RuntimeInformation.dll").GetName().Version

在我們的例子中是:

Major  Minor  Build  Revision
-----  -----  -----  -------- 
4      0      1      0

在app.config中,NuGet編寫了4.0.2.0,因此我們將其更改為4.0.1.0:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>

一切都按照預期自動進行了。

因此,確保使用哪種綁定的唯一方法是使用上述方法自己檢查版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM