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

mongodb-csharp-driver throwing NullReferenceException when using CountAsync

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: API
    • Labels:

      Description

      REF: https://groups.google.com/forum/#!topic/mongodb-user/yfbzkozHS64

      Hi,

      Perhaps I'm not use this method properly but I think I am. Here is my code:

      IMongoCollection<TType> c = _database2.GetCollection<TType>("MyDocuments");
      var f1 = new FilterDefinitionBuilder<TType>();
      var fluent = c.Find(f1.Text(queryFilter.SearchTerm));
      var result = fluent.CountAsync();
      

      When CountAsync executes (I normally would attach a .Result, but I wanted to isolate the issue here), it throws the following exception:

      Object reference not set to an instance of an object.
      at MongoDB.Driver.FindFluent`2.CountAsync(CancellationToken cancellationToken)
      at ProfileUnity.Mongo.Db.MongoDatabaseManager.<>c__DisplayClass9`1.<GetAll>b__8() in d:\work\proudotnet\src\ProfileUnity.Mongo.Db\MongoDatabaseManager.cs:line 192
      

      I should mention that when I comment out the CountAsync() and replace it with:

      var result = fluent.ToListAsync().Result

      My correct results are returned. Any advice?

      Thanks

        Attachments

          Activity

            People

            Assignee:
            craiggwilson Craig Wilson
            Reporter:
            jeremyh Jeremy Herman
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: