ContentAs<string> or QueryAsync<string> fails: Newtonsoft.Json.JsonReaderException: 'Error reading string'

When I try the Query API, or when I use the Key Valye operations, the SDK does not seem to allow me to get the raw string data. Instead, Newtonsoft (used by Couchbase SDK I assume) throws an exception.

The code I tried:

string query = $"SELECT * FROM myCollection WHERE CustomId= {r.Next(1, 100000)}";
await scope.QueryAsync<dynamic>(query); // <--- works!
await scope.QueryAsync<JObject>(query); // <--- works!
await scope.QueryAsync<string>(query); // <--- FAILS!


var result = await collection.GetAsync(key);
var content = result.ContentAs<string>(); // <-- FAILS!

The data is a valid JSON document, that has been verified, but the SDK does not allow me to parse it as raw string, for some reason?

Hello @wagger just noticed this SDK question in an different category

I am assuming its a .NET SDK looking at the code you have posted.
Which SDK version are you using and how does your document look like ?

This is actually answered in another thread I found here:

1 Like