Yet another System.Runtime.InteropServices error

后端 未结 3 1671
自闭症患者
自闭症患者 2021-01-04 03:29

Every project we have with MongoDB will, at one point of another, have a problem with the System.Runtime.InteropServices library that doesn\'t load.

This time the er

相关标签:
3条回答
  • 2021-01-04 03:57

    I found a solution to this problem by uninstalling every mongodb nuget library that need the nuget package System.Runtime.InteropServices.RuntimeInformation and reinstalling it. In my case it was mongodb nuget package.

    After, I upgraded the System.Runtime.InteropServices.RuntimeInformation to 4.3 and add the following in app.config even it's doesn't make sense :

    <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" />
    

    0 讨论(0)
  • 2021-01-04 04:00

    Targeting framework 4.7 or 4.7.1 would resolved the problem. This is because there are some conflicts at the side of .net standard 2

    0 讨论(0)
  • 2021-01-04 04:11

    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

    • System.Runtime.InteropServices.RuntimeInformation v4.3.0
    • System.Runtime.InteropServices v4.3.0

    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.

    I'm probably way off, but my own experiences/observations suggested that MongoDB.Driver (v2.4.4) has a dependency on System.Runtime.InteropServices.RuntimeInformation, which is satisified by its NuGet dependency on NETStandardLibrary, but that System.Runtime.InteropServices.RuntimeInformation's dependency on System.Runtime.InteropServices isn't taken care of. That's why it's not enough to just upgrade RuntimeInformation. In my case I have many projects that already have a dependency on NETStandardLibrary (v1.6) and so I couldn't use System.Runtime.InteropServices.RuntimeInformation v4.0.0 if I wanted to as 4.3.0 is already installed and can't be removed. I saw both the exceptions that you saw, at different times, and installing both the NuGet packages as above resolved them.

    0 讨论(0)
提交回复
热议问题