0

I'm trying to set up a simple sample Couchbase setup, communicating over the C# client, but it's giving me fits. I've installed Couchbase and added a memcached bucket. Here is my simple code for communicating with it:

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");
}

Here is my 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>

The error is a null reference exception with no inner exception details. The stack trace is:

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

Why is this simple configuration failing?

Jeffrey Hantin
  • 35,734
  • 7
  • 75
  • 94
Jim
  • 4,509
  • 16
  • 50
  • 80
  • Include more of the stacktrace, gist it or something if its super large. Also have you tried the uri as 'http://127.0.0.1:8091/pools' ? This answer is probably relevant looking at your problem http://stackoverflow.com/questions/12677445/unable-to-get-enyim-caching-memcachedclient-to-work-with-couchbase?rq=1 – scalabilitysolved Feb 05 '14 at 22:12
  • @scalabilitysolved I included the full stack trace, and I have tried the uri you mentioned, but it didn't change anything. – Jim Feb 05 '14 at 22:28

1 Answers1

4

Your problem is the App.config is not structured correctly and you are not specifying port 8091 in your bootstrap 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>

That should work correctly. Your specific problem was the <startup> element wasn't lined up correctly - note that if there is a <configSections> section it must be the first element after <configuration>.

Jeffrey Hantin
  • 35,734
  • 7
  • 75
  • 94
jeffrymorris
  • 464
  • 3
  • 3