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

NullReferenceException when serializing an Id without a getter

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Unknown Unknown
    • 2.13.0
    • None
    • None
    • None
    • Fully Compatible

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: