Uploaded image for project: 'Couchbase .NET client library'
  1. Couchbase .NET client library
  2. NCBC-1155

DefaultSerializer.GetMemberName throws NullReferenceException if ContractResolver is null

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Minor
    • None
    • 2.3.1
    • library
    • None

    Description

      From https://github.com/couchbaselabs/Linq2Couchbase/issues/150

      If possible, it should fallback to the default contract resolver behavior used by Json.Net if no specific contract resolver is defined. If this isn't possible, then we should throw a more meaningful exception in GetMemberName.

      Message from issue #150:

      Assuming this code:

      var config = new ClientConfiguration();
      var jsonSettings = new JsonSerializerSettings
      {
             Binder = SerializationBinder,
             TypeNameHandling = TypeNameHandling.All,
      };
      config.Serializer = () => new DefaultSerializer(jsonSettings, jsonSettings);
      var cluster = new Cluster(config);
      var bucket = cluster.OpenBucket("MyBucket");
      var context = new BucketContext(bucket);
      

      Queries will fail at this line:

              //ExtendedTypeSerializerMemberNameResolver.cs
       
              public bool TryResolveMemberName(MemberInfo member, out string memberName)
              {
                  memberName = null;
       
                  if (member == null)
                      return false;
       
                  memberName = _serializer.GetMemberName(member);  //BOOM, here
       
                  return memberName != null;
              }
      

      By setting a ContractResolver = new CamelCasePropertyNamesContractResolver() on the json settings, this problem is resolved.

      The BucketContext should probably throw if the client configuration does not provide the above.

      Attachments

        Issue Links

          Activity

            People

              jmorris Jeff Morris
              btburnett3 Brant Burnett
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty