nuget包重新定向后无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation'

时间:2019-07-24 12:46:47

标签: c# .net xunit

关于此错误,有许多类似的帖子,很遗憾,它们都没有帮助。

我已将解决方案项目升级到.NET 4.8,然后发布了command to retarget nuget packages

update-package -reinstall -ignoreDependencies

此后,单元测试失败并显示错误:

  

消息:System.IO.FileNotFoundException:无法加载文件或   程序集'System.Runtime.InteropServices.RuntimeInformation,   版本= 4.0.2.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'或   它的依赖项之一。该系统找不到指定的文件。   ---- System.IO.FileNotFoundException:无法加载文件或程序集'System.Runtime.InteropServices.RuntimeInformation,Version = 4.0.0.0,   文化=中性,PublicKeyToken = b03f5f7f11d50a3a'或其中之一   依赖性。系统找不到指定的文件

融合日志输出如下:

*** 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. Update app.config, add binding redirects
  2. Update System.Runtime.InteropServices.RuntimeInformation v4.3.0 & ystem.Runtime.InteropServices v4.3.0在所有直接或间接引用MongoDB的项目中。
  3. Add System.Runtime & System.Runtime.InteropServices.RuntimeInformation binding redirects

从Fusion日志来看,它会查找GAC,但找不到程序集(我可以确认v。4.0.2.0位于GAC_MSIL中)。

如何摆脱这个错误?

3 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,CAD bloke's answera similar question 提供了对我有用的解决方案:

具体来说,我必须从我的项目中删除 System.Runtime.InteropServices.RuntimeInformation NuGet 包。事实证明,它包含在 .Net >= 4.71 中,因此无需显式添加包。

答案 1 :(得分:0)

当我在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文件夹中 下载 here file

答案 2 :(得分:-1)

我有类似的项目设置,并且遇到了如上所述的类似问题(单元测试因类似错误而失败)。 NuGet包结构已针对System.Runtime.InteropServies.RuntimeInformation v4.3.0进行了更改。我没有在项目中升级此NuGet软件包,而是升级了项目中所有其他软件包。此后,我所有的单元测试都成功通过了。

我不建议您这样做,但是如果有时间限制,这种方法很有用。