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

NullReferenceException when serializing an Id without a getter

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.13.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible

      If an object has an Id property without a getter, attempting to serialize it to json will throw a NullReferenceException. This is caused by not checking if `GetMethod` is null here: https://github.com/mongodb/mongo-csharp-driver/blob/c8e76e5dd3c11683b5d99f56374754eb1e7ec792/src/MongoDB.Bson/Serialization/Conventions/NamedIdMemberConvention.cs#L114-L118.

      I've attached a trivial repro that you can run and test locally.

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: