【问题标题】:Simple Couchbase with C# client setup failing带有 C# 客户端设置失败的简单 Couchbase
【发布时间】:2014-03-02 13:35:54
【问题描述】:

我正在尝试设置一个简单的示例 Couchbase 设置,通过 C# 客户端进行通信,但它让我很适应。我已经安装了 Couchbase 并添加了一个 memcached 存储桶。这是我与之通信的简单代码:

public static void MemcachedTest()
{
    CouchbaseClient client = new CouchbaseClient(); // failure point!
    client.Store(Enyim.Caching.Memcached.StoreMode.Set, "Testing", "Hello world");
    var test = client.Get("Testing");
}

这是我的 app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
  <configSections>
    <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
  </configSections>
  <couchbase>
    <servers bucket="testbucket">
      <add uri="http://127.0.0.1"/> // tried lots of different values here.
    </servers>
  </couchbase>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

错误是没有内部异常详细信息的空引用异常。堆栈跟踪是:

at Couchbase.CouchbaseClient..ctor(ICouchbaseClientConfiguration configuration)
at Couchbase.CouchbaseClient..ctor()
at CacheClientTests.Program.MemcachedTest() in C:\Dev\Experiments\CacheClientTests\CacheClientTests\CacheClientTests\Program.cs:line 72
at CacheClientTests.Program.Main(String[] args) in C:\Dev\Experiments\CacheClientTests\CacheClientTests\CacheClientTests\Program.cs:line 79
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

为什么这个简单的配置会失败?

【问题讨论】:

  • 包括更多的堆栈跟踪,如果它超大的话,它或其他东西。你也试过 uri 作为 '127.0.0.1:8091/pools' 吗?这个答案可能与您的问题有关stackoverflow.com/questions/12677445/…
  • @scalabilitysolved 我包含了完整的堆栈跟踪,我已经尝试了你提到的 uri,但它没有改变任何东西。

标签: c# couchbase enyim


【解决方案1】:

您的问题是 App.config 的结构不正确,并且您没有在引导 URI 中指定端口 8091:

<configuration>
  <configSections>
    <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
  </configSections>
  <couchbase>
    <servers bucket="testbucket">
      <add uri="http://127.0.0.1:8091/pools"/> 
    </servers>
  </couchbase>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这应该可以正常工作。您的具体问题是 &lt;startup&gt; 元素没有正确排列 - 请注意,如果有 &lt;configSections&gt; 部分,它必须是 &lt;configuration&gt; 之后的第一个元素。

【讨论】:

    猜你喜欢
    • 2020-06-16
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多