Error using MapAdd/MapGet

I am having trouble trying to use the map in IBucket. I can connect to the bucket and I have beem able to insert/upsert with documents. Right now, I’m trying to create map and id/content to it if the id didn’t exsist in the bucket. If the same id exsists, I want to add the new id/content previous document.


ClusterHelper.Initialize(new ClientConfiguration
    Servers = new List<Uri> { new Uri("couchbase://localhost") }

var bucket = ClusterHelper.GetBucket("something");

string stringExample = "some strings";
if (!bucket.Exists("SerialNumber"))
         bucket.MapAdd("SerialNumber", "mapKey", stringExample, true);
         var insert = bucket.MapGet<string>("SerialNumber", "mapKey");  //I tried<dynamic> as well
         bucket.Insert(beacon.SerialNumber, insert);
          bucket.MapAdd("SerialNumber", "mapKey", stringExample, false);
          var upsert = bucket.MapGet<dynamic>("SerialNumber", "mapKey");
          bucket.Upsert("SerialNumber", upsert);

it’s throwing exception at the MapGet statement, "‘System.NullReferenceException’ occurred in Couchbase.NetClient.dll ".
The MapAdd has “Info = ‘((Couchbase.Cluster)((Couchbase.CouchbaseBucket)bucket).Cluster).Info’ threw an exception of type ‘System.InvalidOperationException’”

krnforsale -

Which SDK version?

I was able to reproduce the error in 2.4.2 and created a Jira ticket. The problem is that document doesn’t exist so MapGet returns a status of KeyNotFound (as does MapAdd) which causes the NRE when the body of the MapGet is deserialized because the body is null.

We should have a fix by 2.4.3; the work around is to create the document before using the MapXXX methods.


Thanks for the reply. I actually figured it out! hah. Now I’m stuck on something else. I’m trying to enter a string into the value for the MapAdd. I am not able to query it in the couchbase workbench. I’m not sure what format the string has to be in for it to come up nice and pretty.


String finalData = "‘BluetoothAddress’: object.BluetoothAddress, ‘Id’: object.Id, ";
bucket.MapAdd(“SerialNumber”, “mapKey”, finalData , true);

I’m new to programming in general, thanks for helping me out.

I am not sure what the qualification is for “nice and pretty”. In the example you have a string literal, but it looks like you wanted the value of object.BlueToothAddress and object.Id?