Find() fails with "Object reference not set to an instance of an object."

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 2.4.1
    • Affects Version/s: 2.0
    • Component/s: API
    • None
    • Environment:
      VS2013, Windows 7
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The following code fails with NullReference exception:

      int? key = null;
      collection.Find(r => r.RequestId == requestId && (key == null || r.Key == key)).Limit(1).FirstOrDefaultAsync();
      
      // Class, stored in collection
      public class Request
      {
         public string RequestId {get; set;}
         public int Key {get; set;}
      }
      

      Stack trace attached.

      Apparently, the problem is that the serializer selected based on the document property type, which is INT, rather than on the actual value type, which is INT?. Therefore, it later fails on NULL value, hence serializer expects ValueType, rather than reference type.

              Assignee:
              Robert Stam
              Reporter:
              Sergey Ivasenko
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: