DotNet SDK 3.0.7
I am trying some code samples right from SDK 3.0 documentation: Transcoders and Non-JSON Documents | Couchbase Docs and getting InvalidOperationException:The RawBinaryTranscoder can only decode byte arrays on ContentAs. What am I missing here?
My complete code:
static async Task Main(string args)
{
ICluster _cluster = await Cluster.ConnectAsync(“couchbase://192.168.0.6”, “test”, “test”);
var docId = “doc”;
var bytes = System.Text.Encoding.UTF8.GetBytes(“hello world”);
var bucket = await _cluster.BucketAsync(“TEST”);
var _collection = bucket.DefaultCollection();
await _collection.UpsertAsync(docId, bytes, options => options.Transcoder(new RawBinaryTranscoder()));
var result = await _collection.GetAsync(docId, options => options.Transcoder(new RawBinaryTranscoder()));
var returned = result.ContentAs<byte>();
string s = System.Text.Encoding.UTF8.GetString(returned);
Console.WriteLine(s);
}
Looking at the SDK code, it appears that for the RawBinaryTranscoder to work the data must also be flagged as binary on the server. You might try using the RawStringTranscoder, since you’re decoding the byte array to a string anyway.