AppFabric 1.0错误服务器集合不能为空

时间:2012-11-07 22:01:57

标签: c# asp.net appfabric windows-server appfabric-cache

运行简单的 Windows Server App Fabric 1.0 演示控制台应用程序时出现以下错误:

ErrorCode<ERRCA0021>:SubStatus<ES0001>:Server collection cannot be empty.

请帮帮我..我错过了什么.. ??我已经看过互联网上的每一个地方,似乎没有什么能解决这个问题。感谢..

我的申请如下:

static void Main(string[] args)
{
    var factory = new Microsoft.ApplicationServer.Caching.DataCacheFactory(); <--- *** Error here

    var cache = factory.GetDefaultCache();
    var key = "mykey";
    var obj = cache[key];
    if (obj == null)
    {
        cache[key] = "I am data for caching";
    }
    obj = cache[key];
    Console.WriteLine(obj);
    Console.Read();
}

我的app.config如下:

<?xml version="1.0"?>
<configuration>
<configSections>
    <section name="dataCacheClients"
                type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" /> 
</configSections>
<dataCacheClients>
<dataCacheClient>
    <hosts>
        <host name="MyMachineNameHere" cachePort="22233" />
    </hosts>
</dataCacheClient>
</dataCacheClients>
</configuration>

1 个答案:

答案 0 :(得分:3)

我按照以下方式更新了我的appconfig,它有效....

<?xml version="1.0"?>
<configuration>

    <!--configSections must be the FIRST element -->
    <configSections>
        <!-- required to read the <dataCacheClient> element -->
        <section name="dataCacheClient"
            type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
            Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, 
            Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            allowLocation="true"
            allowDefinition="Everywhere"/>
    </configSections>

    <!-- cache client -->
    <dataCacheClient>
        <!-- cache host(s) -->
        <hosts>
            <host
               name="MyMachineNameHere"
               cachePort="22233"/>
        </hosts>
    </dataCacheClient>


</configuration>