RawBinaryTranscoder problem

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.

Looks like the server knows the data is binary. Also I need it for binary data. The string here is coming from SDK doc sample.

I believe that document is actually encoded as a Private data format (lower bits of flags = 1, not 3). However, regardless, it should work.

It appears that it’s a known bug which has been fixed for the next release: https://github.com/couchbase/couchbase-net-client/commit/0913ff1a4fb6d3202ee5408343e021373182a489#diff-5453e0f28a6f33806dd83565adf020c393637b16023e745c4cea3ec460f3d3b6

Until then, you might try the LegacyTranscoder. Looking at the logic I think it will work for you.

Off the topic but .RawStringTranscoder example from the same document. does not work either :frowning: System.InvalidOperationException: 'The RawStringTranscoder can only decode strings.'https://docs.couchbase.com/dotnet-sdk/current/howtos/transcoders-nonjson.html#rawstringtranscoder

@skaryshev

You’re right, it does have the same problem. It appears to have been fixed in the same change that fixed RawBinaryTranscoder.