GetJson<T> throwing NullReferenceException

I have been using the Couchbase .NET Client 1.2.1.0 for at while, and the behavior that gave me with the GetJson<T> method was, that if the key did not exist, it returned default(T). But after upgrading to 1.2.7.0 I now get a NullReferenceException, if the key does not exist.

On top of that, I cannot store a simple string value with StoreJson and fetch it afterwards using GetJson<string>, as I here get some kind of JSON parsing error.

Can anyone shed light on, what has happened to the previous (and in my opinion, correct) behavior of the JSON extensions?

Regards

3 Answers

« Back to question.

Hi Thomas,

I haven't tried to reproduce the error and you haven't provided a stack trace, but looking at the source for GetJson<T> it looks a bit funky.

Line 105: https://github.com/couchbase/couchbase-net-client/blob/master/src/Couchb...

If this underlying call returns null, the DocHelper will crash since it tries to access null.Contains. But the code in line 106, kind off implies that JSON should be able to be null. A bit confusing and I don't know (since I haven't tried it) if it's as simple as not invoking the DocHelper, but since it's an extension method, you could replicate the code your self, right, and see if that solves the issue.

Anyway, I'm sure someone at Couchbase will attend this soon otherwise.

Cheers,

//Daniel

« Back to question.

It should be easy to reproduce with an empty Couchbase bucket and a simple call to GetJson<T>. Version 1.2.1.0, which we are using, returns default(T), however the new 1.2.7.0 (from NuGet) throws an exception.

Are you able to reproduce this behavior?

« Back to question.

There were some changes to dependencies in trying to simplify the client, but to my knowledge there is nothing that should have broken API. Do you have a simple test case by chance that shows the problem without your actual data?