1. Hi I've been working on a library similar to the MySQL library oxide provides. I have all of the framework written, but I'm having an issue with getting the library to run. The server.log gives me this error hastebin. There seems to be some kind of issue with the System.Runtime.InteropServices.RuntimeInformation.dll dependency which I have in my RustDedicated_Data/Managed/ folder.

    A quick google search online shows that this a pretty common issue when working with MongoDB, but none of their solutions have helped. The library compiles successfully and I have put the Oxide.MongoDB.dll in the RustDedicated_Data/Managed/ folder as well as MongoDB.Bson.dll, MongoDB.Driver.dll and MongoDB.Driver.Core.dll. MongoDB.Driver.Core.dll depends on System.Runtime.InteropServices.RuntimeInformation so I have put that dll in the folder as well.

    According to the error it is looking for version 4.0.0.0, but I have tried using both of these versions. https://i.imgur.com/kkNdxDk.png. I can't figure out why the server is unable to load System.Runtime.InteropServices.RuntimeInformation.

    People have suggested online that you need to add this to your app.config, but it didn't make a difference.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <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>
            </assemblyBinding>
        </runtime>
    </configuration>
    Any help would be appreciated. Thank you for your time!
     
    Last edited by a moderator: Jun 12, 2018
  2. Target your solution for .NET Framework 4.x not 2.0

    Make sure the MongoDB drivers you're getting are also the matching .NET Framework version.

    If you're using NuGet I believe it automatically obtains the libraries that your solution is targeted for.

    Also nice to see someones working on this, hope you decide to PR it :p
     
  3. I was planning on submitting a PR once I got everything up an running and I changed my library to be a little more abstract.

    My solution targets .NET Framework 4.6.

    According to this website MongoDB has been compatible with .NET 4.6 since version 2.0 of the C# driver.

    I am uploading the version of System.Runtime.InteropServices.RuntimeInformation that NuGet produces when I build the library. I have even opened the dll in dotPeek and the Version and PublicKeyToken match so I believe I have the correct dll.

    I am having a hard time understanding why the dll won't be found. Is it possible that System.Runtime.InteropServices.RuntimeInformation does not work on Ubuntu? I am also wondering about the second part of the error where it says or one of its dependencies
    Code:
    Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies
    How could I go about investigating whether or not it's a dependency of RuntimeInformation that's an issue rather than the dll itself?

    I was also wondering where the main app.config file is so I can test using a bindingRedirect on the dependency. I don't think class libraries would run this xml. I think I need to find the main application config and add this xml.
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705">
          <dependentAssembly>
            <assemblyIdentity name="System.Runtime" publicKeyToken="b03fS5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    Sorry for all the questions I've been working on fixing this all day and I just have no idea where to start in finding a solution.
     
  4. The error I am still getting if anyone hasn't seen it.

    I think I may have found this issue, however, I'm not 100% sure how .Net Framework compatibility works. All of the system dlls in the Managed directory are compiled against .Net Framework v4.0. Mongo was compiled against .Net Framework v4.5 and is not compatible with with the project if I target v4.0 I also saw from Microsoft(link) that System.Runtime.InteropServices.RuntimeInformation was introduced in .Net Framework v4.7.1. What I don't understand is why it said in the Dev Blog "Upgraded to .NET 4.x". Shouldn't that mean any library targeted against .Net Framework v4.x should work? I've actually compiled an extension against 4.7.2 and it worked just fine just without Mongo referenced in the project. I think Upgraded to .Net 4.x means that we can use the new language features, but anything added recently such as System.Runtime.InteropServices.RuntimeInformation won't work because it needs a newer version of the system dlls.

    I've tried updating those system dlls in the Managed folder, but that causes errors so I don't think it's possible to run MongoDB. It's just really odd to me that the error I get only says
    Code:
    FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
    when it's clearly there. When I tried to get MongoDB working before the updated to 4.x it gave me a different error basically saying there was a version mismatch.

    I've been trying to research how .Net Framework compatibility works, but this case seems very specific and it's hard to find information to help.

    It seems that all of the System dlls in the Managed directory where compiled against .Net Framework v4.0 not against 4.5 or higher. According to Microsoft System.Runtime.InteropServices.RuntimeInformation has only been available since version 4.7.1 and version 4.0.0.0 of System.Runtime.InteropServices.RuntimeInformation is targeted against .Net Framework v4.7.2. It's very unclear how compatibility in .Net works because in the dev blog said they upgraded to "Upgraded to .NET 4.x" which means that MongoDB which was targeted against 4.5 and not compatible with .Net 4.0 should be compatible, but I don't think it is because updating the System dlls to anything newer causes errors.

    I've been working on this problem for a couple days so any insight about the issue would be helpful because I'm not very knowledgeable about the .Net Framework in terms of compatibility. I guess my main question is if version 4.0.0.0 of System.Runtime.InteropServices.RuntimeInformation that's targeted against .Net Framework 4.7.2 is not compatible with .Net Framework 4.0 system dlls would I get this error? Or would I get another error telling me they don't work together? The exception seems to imply it just can't find the dll, but it's clearly there with the proper version.
     
    Last edited by a moderator: Jun 14, 2018
  5. I finally decided to clone the mongo-csharp-driver repository and tried to fix it. I only had to remove the reference to System.Runtime.InteropServices.RuntimeInformation.dll and fix a couple of errors. It build no problem and now my extension is working! I wish I would have tried to do this earlier, it was such a simple fix. .net 4.0 already has methods to do the same thing as the code RuntimeInformation does. If anyone needs a download to the driver let me know!

    I know this isn't a perfect solution because I still don't understand why the RuntimeInformation dll wouldn't load, but it's working and I've spent far too long working on this. For anyone curious this post isn't exactly relevant to my issue, but it motivated me to try and fix the driver myself.
     
    Last edited by a moderator: Jun 14, 2018