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” 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.
|For Gerrit Dashboard: NCBC-1150|
|65411,3||NCBC-1150: Lookup fails when getting hierarchical subdocument||master||couchbase-net-client||Status: MERGED||+2||+1|