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

Subdocument - Lookup fails when getting hierarchical subdocument



    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.3.1
    • 2.3.3
    • library
    • .NET, Windows


      Summary: When getting a subdocument that isn't a simple value, the .NET library fails with InvalidOperationException.


      1. Create document with at least one hierarchical property
      2. Perform a subdocument lookup on that property.
      (see attached code sample)

      Success, the subdocument to be returned.

      InvalidOperationException, no indication of what the user did wrong.

      I emailed this to Jeff:

      I’ve stepped through the code just to see if I could figure out what’s going on. I might have found a bug?

      In this line of MultiLookup.cs: https://github.com/couchbase/couchbase-net-client/blob/master/Src/Couchbase/IO/Operations/SubDocument/MultiLookup.cs#L103

      It’s passing the length of the body to IsJson. So if the byte array is 50, it passes 50.

      But in IsJSON, that parameter is called “endIndex”, and is passed directly to the byte array indexer: https://github.com/couchbase/couchbase-net-client/blob/master/Src/Couchbase/Utils/ArrayExtensions.cs#L184

      This means that in some situations (like the one I’m encountering, maybe), it will try “theArray[50]” on an array that is size 50. Hence the ‘out of range’ exception. It doesn’t ALWAYS happen because that code might short circuit. It also seems like an odd/imprecise way to determine if a byte array is JSON or not. I would assume you’d encode it to a string and use JSON.net to determine. But maybe it’s an optimization?

      Just for fun, I changed “endIndex” to “endIndex-1” inside of IsJSON, and now it works.

      I don’t know if that’s the right fix, but I think it must be a bug.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.


          matthew.groves Matthew Groves created issue -
          jmorris Jeff Morris made changes -
          Field Original Value New Value
          Status New [ 10003 ] Open [ 1 ]
          jmorris Jeff Morris made changes -
          Fix Version/s 2.3.2 [ 13438 ]
          jmorris Jeff Morris made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          jmorris Jeff Morris made changes -
          Fix Version/s 2.3.3 [ 13439 ]
          Fix Version/s 2.3.2 [ 13438 ]


            jmorris Jeff Morris
            matthew.groves Matthew Groves
            0 Vote for this issue
            2 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes