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

NullReferenceException when calling Set in an update pipeline

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Dotnet Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      When attempting to run the code below a NullReferenceException is thrown

      Driver: 2.24.0

      How to Reproduce

      Run the following test:

      
      

      _public class MongoTest
      {
          [Fact]
          public async Task Test()
          {
              var settings = MongoClientSettings.FromConnectionString("

      {ConnectionString}

      ");
              settings.ServerApi = new ServerApi(ServerApiVersion.V1);
              settings.LinqProvider = MongoDB.Driver.Linq.LinqProvider.V3;        var mongoClient = new MongoClient(settings);        var db = mongoClient.GetDatabase("DB");        var collection = db.GetCollection<Record>(nameof(Record));        var result = await collection.UpdateOneAsync(
                  Builders<Record>.Filter.Empty,
                  Builders<Record>.Update.Pipeline(PipelineDefinitionBuilder.For<Record>()
                      .Set(record => new Record
                      {
                          DurationInMinutes = DateTime.UtcNow.Subtract(record.StartTime, DateTimeUnit.Minute)
                      })));
          }    private class Record
          {
              public DateTime StartTime

      { get; set; }

              public double DurationInMinutes { get; set; }
          }
      }_

       

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            wassimk@vypex.com Wassim Khalil
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: