Tho*_*mas 10 .net c# interop windows-runtime
我们与MongoDB一起使用的每个项目都会在没有加载的System.Runtime.InteropServices库中出现问题.
这次错误很有趣:
外部异常找不到lib的4.3.0.0版本.但是内部异常找不到版本4.0.0.0
有没有人对此有所了解?
有关此问题的更多信息:
所以,NuGet已经安装了4.3.0.0
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Runtime" version="4.3.0" targetFramework="net462" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />
</packages>
Run Code Online (Sandbox Code Playgroud)
packages.config确认我已经安装了4.3.0.0,
然而,app.config似乎总是与现实不同步:
<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>
Run Code Online (Sandbox Code Playgroud)
添加了关于版本4.0.1.0的一行
在同一行.. csproj是胡说八道:
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>x:\Packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)
因为它声称引用4.0.1.0的路径为4.3.0.0
有一些东西被破坏了,它总是发生在那个完全相同的lib上; 不仅仅是这个项目:在我包含MongoDB的任何地方,这个lib都是一个依赖项,每次都有一些随机问题.
当我尝试手动加载时:
var Name = new AssemblyName("System.Runtime.InteropServices.RuntimeInformation, Version=4.3.0.0");
var Asm = Assembly.Load(Name);
Run Code Online (Sandbox Code Playgroud)
它也失败了.
我发现System.Runtime.InteropServices.RuntimeInformation.dll不会被复制到build文件夹,即使它包含在项目中.
我找到了一个讨厌的解决方法:如果我在主exe中包含MongoDB,即使我不使用它,它依赖于Interop lib,这迫使lib被复制到build文件夹,然后后续调用工作.
The System.Runtime.InteropServices.RuntimeInformation v4.3.0 NuGet does indeed install a DLL with the version 4.1.0.0; although confusing it doesn't seem to create any problems.
Try installing the following NuGets on each project that directly or indirectly uses MongoDB v2.4.4
This worked for me.
The only case where this didn't work was an MSTest unit/integration test where MSTest appears to ignore binding redirects (seperate issue - seems to be quite common), as such I created my integration test using a regular console exe.
我可能还很遥远,但我自己的经验/观察表明 MongoDB.Driver (v2.4.4) 依赖于 System.Runtime.InteropServices.RuntimeInformation,它通过其 NuGet 对 NETStandardLibrary 的依赖来满足,但是 System.Runtime .InteropServices.RuntimeInformation 对 System.Runtime.InteropServices 的依赖关系未被处理。这就是为什么仅仅升级 RuntimeInformation 是不够的。就我而言,我有许多项目已经依赖于 NETStandardLibrary (v1.6),因此如果我想的话,我无法使用 System.Runtime.InteropServices.RuntimeInformation v4.0.0,因为 4.3.0 已经安装并且可以使用不被删除。我在不同时间看到了您看到的两个异常,并按照上面的方式安装两个 NuGet 包解决了它们。