Простая Couchbase с настройкой клиента C# не удалась

Я пытаюсь настроить простой пример установки Couchbase, общаясь через клиент C#, но это мне подходит. Я установил Couchbase и добавил Memcached Bucket. Вот мой простой код для общения с ним:

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()

Почему эта простая конфигурация не работает?

1 ответ

Ваша проблема в том, что файл App.config неправильно структурирован, и вы не указываете порт 8091 в URI начальной загрузки:

<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>

Это должно работать правильно. Ваша конкретная проблема была <startup> элемент не был выстроен правильно - обратите внимание, что если есть <configSections> раздел должен быть первым элементом после <configuration>,

Другие вопросы по тегам