序列化CouchbaseClient错误

时间:2014-03-14 07:49:11

标签: c# couchbase

是否可以序列化CouchbaseClient以将其写入内存映射文件?

当我尝试这样做时:

[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;
    }
}

我得到了Couchbase.CouchbaseClient的SerializationException。如果可以序列化将如何完成。 Couchbase.CouchbaseClient是通过NuGet安装的。

如何在线程中共享Couchbase.CouchbaseClient?

1 个答案:

答案 0 :(得分:1)

官方文档专门介绍了如何实例化和共享单个客户端实例。我会按照最佳做法进行操作,您可以在此处找到http://docs.couchbase.com/couchbase-sdk-net-1.3/#instantiating-the-client

链接

此处还有一些关于C#客户端的详细信息:http://docs.couchbase.com/couchbase-sdk-net-1.2/#encapsulating-data-access

相关问题