timkado
timkado

Reputation: 2052

Missing Method Exception MongoDB C# driver

I am getting the following error with the latest MongoDB C# driver.

System.MissingMethodException MongoDB.Bson.GuidRepresentationMode MongoDB.Bson.BsonDefaults.get_GuidRepresentationMode()

The exception occurs in MongoClient:

var client = new MongoClient("mongodb+srv://____:___@_____.nrzff.mongodb.net/____?retryWrites=true&w=majority");
var database = client.GetDatabase("ResultsModelSummary");
var collection = database.GetCollection<BsonDocument>("Zones");   
var bsonDocList = new List<BsonDocument>();
foreach (var r in resModSums) {
    var bsonDoc = BsonDocument.Parse(Serialization.Serialize<ResultsModelSummary>(r));
    bsonDocList.Add(bsonDoc);
}

collection.InsertManyAsync(bsonDocList);   

public class ResultsModelSummary
    {
        // META
        public string RunID { get; set; } // this is a stringified GUID
        public string TimeStamp { get; set; }
        // more fields .....
    }

The exception actually occurs irregularly. Sometimes the above code works fine.

Any suggestions?

Adding more information:

System.MissingMethodException HResult=0x80131513 Message=Method not found: 'MongoDB.Bson.GuidRepresentationMode MongoDB.Bson.BsonDefaults.get_GuidRepresentationMode()'.
Source=MongoDB.Driver StackTrace: at MongoDB.Driver.MongoUrl..ctor(String url) at MongoDB.Driver.MongoClient..ctor(String connectionString) at EnergyMLGH.MongoDB.<>c__DisplayClass1_0.b__0() in C:\Users...\MongoDB.cs:line 52 at System.Threading.Tasks.Task.Execute()

Screenshot of exception

Upvotes: 2

Views: 2961

Answers (1)

craday
craday

Reputation: 51

I had the same problem, and it turned out that I had MongoDB references with different versions. I removed the references and added them back, making sure that the versions were all the latest ones and voila, it started working.

Upvotes: 4

Related Questions