2014-02-05 42 views
0

我想設置一個簡單的示例Couchbase安裝程序,通過C#客戶端通信,但它給我適合。我已經安裝了Couchbase並添加了一個memcached存儲桶。這是我與它通信簡單的代碼:簡單Couchbase與C#客戶端安裝程序失敗

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

爲什麼這個簡單的配置失敗?

+0

包含更多的堆棧跟蹤,如果超級大,請將它或東西包含在內。你有沒有嘗試使用uri作爲'http://127.0.0.1:8091/pools'? 這個答案可能是相關看你的問題http://stackoverflow.com/questions/12677445/unable-to-get-enyim-caching-memcachedclient-to-work-with-couchbase?rq=1 – scalabilitysolved

+0

@scalabilitysolved我包括完整的堆棧跟蹤,我已經嘗試過你提到的uri,但它沒有改變任何東西。 – Jim

回答

4

你的問題是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>之後的第一個元素。