Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2393

Driver is not compatible with .NET 4.7.1

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.0
    • Component/s: Build
    • None
    • Environment:
      Windows 10, Visual Studio 2017 15.8.5, .NET framework 4.7.1

      I created a simple console app running under .NET 4.7.1, added the MongoDB.Driver nuget package with highest versions dependencies. I end up with a very simple project with the following files:

      • Program.cs
      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      using MongoDB.Bson;
      using MongoDB.Driver;
      using System;
      
      namespace ConsoleApp1
      {
          internal class Program
          {
              private const string connectionString = "xxxxxx";
              private const string databaseName = "xxxxxx";
              private const string collectionName = "test";
      
              private static void Main(string[] args)
              {
                  var mongoUrl = new MongoUrl(connectionString);
                  var mongoClientSettings = MongoClientSettings.FromUrl(mongoUrl);
                  var mongoClient = new MongoClient(mongoClientSettings);
                  IMongoDatabase database = mongoClient.GetDatabase(databaseName);
      
                  long count = database.GetCollection<BsonDocument>(collectionName).CountDocuments(FilterDefinition<BsonDocument>.Empty);
                  Console.WriteLine(count);
                  Console.ReadLine();
              }
          }
      }
      

      * packages.config

      <?xml version="1.0" encoding="utf-8"?>
      <packages>
        <package id="DnsClient" version="1.2.0" targetFramework="net471" />
        <package id="MongoDB.Bson" version="2.7.0" targetFramework="net471" />
        <package id="MongoDB.Driver" version="2.7.0" targetFramework="net471" />
        <package id="MongoDB.Driver.Core" version="2.7.0" targetFramework="net471" />
        <package id="System.Buffers" version="4.5.0" targetFramework="net471" />
        <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net471" />
      </packages>
      

      When I execute this program, I get the following error at runtime:

      System.IO.FileLoadException: 'Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception de HRESULT : 0x80131040)'
      

      The exact same program works when I target .NET framework 4.7 instead of 4.7.1 (and update the package.config accordingly).

      It seems to be related to the fact that .NET 4.7.1 includes the DLL System.Runtime.InteropServices.RuntimeInformation in-box, whereas .NET 4.7 does not. Maybe the Mongo.Driver.Core package should not reference this nuget package when targeting .NET framework 4.7.1.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            mrossini@maskott.com Maxime Rossini
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: