Mike Barnes
Mike Barnes

Reputation: 4305

Serializing CouchbaseClient Error

Is it possible to serialize a CouchbaseClient to write it to a Memory Mapped file?

When I try do this:

[Serializable]
public class DocumentDatabaseConnection
{
    public CouchbaseClient DocumentStoreConnection { get; set; }
}

static void main(string [] args)
{
    CouchbaseClientConfiguration config = new CouchbaseClientConfiguration();
    config.Urls.Add(new Uri("http://localhost:8091" + "/pools/"));
    config.Bucket = "myBucket";
    config.BucketPassword = "123456";

    DocumentDatabaseConnection clientConnection = new DocumentDatabaseConnection();

    clientConnection.DocumentStoreConnection = new CouchbaseClient(config);

    try
    {
        //Here is where I try to convert it to a byte array to save in MMF
        var myMMFObject = ObjectToByteArray(clientConnection);
        WriteObjectToMMF("C:\\TEMP\\TEST.MMF", myMMFObject);
        string myMMF = ReadObjectFromMMF("C:\\TEMP\\TEST.MMF").ToString();
    }
    catch(Exception e)
    {
        throw;
    }
}

I get a SerializationException, for the Couchbase.CouchbaseClient. If it is possible to serialize how would that be done. Couchbase.CouchbaseClient was installed via NuGet.

How would one share a Couchbase.CouchbaseClient accross threads?

Upvotes: 0

Views: 130

Answers (1)

scalabilitysolved
scalabilitysolved

Reputation: 2474

The official documentation specifically covers how to instantiate and share a single client instance. I would follow that for best practices, you can find the link here http://docs.couchbase.com/couchbase-sdk-net-1.3/#instantiating-the-client

Also there is some more detail regarding the client for C# located here: http://docs.couchbase.com/couchbase-sdk-net-1.2/#encapsulating-data-access

Upvotes: 1

Related Questions