I have Mongo's dependencies needed for the project in VisualStudio 2017 Community but an error is generated when instantiating the MongoClient class
Error:
Unable to load the file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' or one of its dependencies. The system can not find the specified file.
Description: Unhandled exception when executing the current Web request. Check the stack trace for more information about the error and where it originated in the code.
Exception details: System.IO.FileNotFoundException: Unable to load the file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a' or one of its dependencies . The system can not find the specified file.
Source code error:
Line 25: var mongoUrl = MongoUrl.Create (connectionString);
Line 27: var client = new MongoClient (connectionString);
Line 29: // Use the Mongo URL to avoid hard-coding the database name.
The code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MongoDB.Bson;
using MongoDB.Driver;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected static IMongoClient _client;
protected static IMongoDatabase _database;
protected void Page_Load(object sender, EventArgs e)
{
//string connectionString = "mongodb://localhost:27017";
//MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(connectionString));
//MongoServerAddress mongoServerAdress = new MongoServerAddress(connectionString);
// Get your connection string -- use the URL format as in example below:
// name="MongoConnectionStr" connectionString="mongodb://localhost/bookstore"
var connectionString = ConfigurationManager.ConnectionStrings["MongoConnectionStr"].ConnectionString;
var mongoUrl = MongoUrl.Create(connectionString);
var client = new MongoClient(connectionString); //<-- Error aquí
// Use the Mongo URL to avoid hard-coding the database name.
var db = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName);
}
}