Netstandard依赖项System.IO.FileNotFoundException

时间:2020-03-26 13:52:44

标签: .net .net-standard .net-standard-2.0

我们有一个.Net Framework 4.7应用程序,该应用程序依赖于该解决方案中针对.NET Standard 2.0的另一个项目。

该项目再次依赖于另一个(外部).NET Standard 2.0库,该库已通过私有Nuget存储库添加。该库依赖Microsoft.Win32进行注册表查找。

调试.Net FW应用程序时,在运行时会收到FileNotFoundException:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

我更改了使用注册表的库,并添加了Microsoft.Win32.Registry包。 再次调试时,错误将更改为其他版本:

Could not load file or assembly 'Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

我们在哪里努力解决这个问题?使用Win32.Registry的库中是否配置错误?还是取决于它的.NET Standard项目?还是在.NET 4.7应用程序的顶层?

2 个答案:

答案 0 :(得分:2)

我建议您右键单击解决方案,然后转到“管理NuGet软件包”,然后转到“合并”选项卡并解决冲突。您可能在多个项目上具有各种版本的库。通常,在解决问题时,库中的错误会一次出现。

答案 1 :(得分:2)

对于任何发现该线程的人,有效的方法就是将外部库使用的win32.registry nuget包也添加到.net Framework 4.7项目中。

甚至认为这还远未达到最佳效果,这是在这种情况下唯一有效的方法,必须这样做。

参考:Why is my .NET framework app looking for the wrong version of the .NET core/standard platform extension assembly, and how do I fix it?

相关问题