簡體   English   中英

nuget 包重定向后無法加載文件或程序集“System.Runtime.InteropServices.RuntimeInformation”

[英]Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation' after nuget package retargetting

關於此錯誤,SO 上有許多類似的帖子,不幸的是,它們都沒有幫助。

我已將解決方案項目升級到 .NET 4.8,然后發出了重新定位 nuget 包命令

update-package -reinstall -ignoreDependencies

在此之后,單元測試失敗並出現錯誤:

消息:System.IO.FileNotFoundException:無法加載文件或程序集“System.Runtime.InteropServices.RuntimeInformation,Version=4.0.2.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依賴項之一。 該系統找不到指定的文件。 ---- System.IO.FileNotFoundException : 無法加載文件或程序集“System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依賴項之一。 該系統找不到指定的文件

Fusion 日志輸出如下:

*** Assembly Binder Log Entry  (7/24/2019 @ 2:20:44 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PROFESSIONAL\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\testhost.x86.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/sources/Services/upgrade-net48/ProSynchronizationWorker.Tests/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\mike\AppData\Local\Temp\d21152b7-1ec9-47aa-88ab-181259a56531
LOG: AppName = d21152b7-1ec9-47aa-88ab-181259a56531
Calling assembly : MongoDB.Driver.Core, Version=2.7.2.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\sources\Services\upgrade-net48\ProSynchronizationWorker.Tests\bin\Debug\ProSynchronizationWorker.Tests.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.0.2.0.
LOG: Post-policy reference: System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/sources/Services/upgrade-net48/ProSynchronizationWorker.Tests/bin/Debug/System.Runtime.InteropServices.RuntimeInformation.DLL.
LOG: Attempting download of new URL file:///C:/sources/Services/upgrade-net48/ProSynchronizationWorker.Tests/bin/Debug/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.DLL.
LOG: Attempting download of new URL file:///C:/sources/Services/upgrade-net48/ProSynchronizationWorker.Tests/bin/Debug/System.Runtime.InteropServices.RuntimeInformation.EXE.
LOG: Attempting download of new URL file:///C:/sources/Services/upgrade-net48/ProSynchronizationWorker.Tests/bin/Debug/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.EXE.
LOG: All probing URLs attempted and failed.

我嘗試了一些建議

  1. 更新 app.config,添加綁定重定向
  2. 在所有直接或間接引用 MongoDB 的項目中更新 System.Runtime.InteropServices.RuntimeInformation v4.3.0 和 ystem.Runtime.InteropServices v4.3.0
  3. 添加 System.Runtime 和 System.Runtime.InteropServices.RuntimeInformation 綁定重定向

從 Fusion 日志來看,它查看了 GAC 但沒有找到程序集(我可以確認 v. 4.0.2.0 在 GAC_MSIL 中)。

我怎樣才能擺脫這個錯誤?

我遇到了同樣的問題, CAD 家伙類似問題的回答提供了對我有用的解決方案:

具體來說,我必須從我的項目中刪除System.Runtime.InteropServices.RuntimeInformation NuGet 包。 事實證明,它包含在 .Net >= 4.71 中,因此無需顯式添加包。

當我在 Windows 服務器上運行我的項目時遇到了同樣的問題,然后它給出了一個錯誤。

Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

然后經過兩天的搜索。 我通過添加解決了這個問題

System.Runtime.InteropServices.RuntimeInformation.dll

在我的項目bin文件夾中下載這里文件

暫無
暫無

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

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