【问题标题】:Error in client configuration file客户端配置文件错误
【发布时间】:2013-04-26 07:44:24
【问题描述】:

我正在尝试创建一个 AppFabric 缓存客户端,它是一个控制台应用程序。但是在创建 DataCacheFactory 的新实例时收到错误 客户端配置文件中的错误。
App.Config 文件中提供了连接设置,如msdn 中所述。
代码

static void Main(string[] args)
{
  try
  {
    DataCacheFactory dFact = new DataCacheFactory();
    DataCache myCache = dFact.GetCache("default");

    myCache.Remove("pValue");
    myCache.Add("pValue", "Test Cache Value");
    Console.WriteLine(string.Format("{0}", "Added to cache. Press any key to read...."));
    Console.ReadLine();
    Console.WriteLine(string.Format("{0}", myCache.Get("pValue").ToString()));
    Console.ReadLine();
  }
  catch (Exception Ex)
  {
    throw new System.Exception(Ex.ToString());
  }

}

}
App.Config 文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<configSections>
<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>
 <dataCacheClient>
 <hosts>
  <host  name="localhost" cachePort="22233"/>
 </hosts>
 </dataCacheClient>
</configuration>


异常

Microsoft.ApplicationServer.Caching.DataCacheException:
ErrorCode<ERRCMC0003>:SubStatus<ES0001>:Error in client configuration file. --->
System.Configuration.ConfigurationErrorsException: Configuration system failed to
initialize ---> 
System.Configuration.ConfigurationErrorsException: 
Only one  <configSections> element allowed per config file 
and if present must be the first child of the root <configuration> element.
(DistributedInMemory.vshost.exe.Config line 7) 
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---

at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at
 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Microsoft.ApplicationServer.Caching.ClientConfigReader..ctor()
at Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(String path)
--- End of inner exception stack trace ---

at Microsoft.ApplicationServer.Caching.ConfigFile.ThrowException(Int32 errorCode, Exception e) 
at Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(String path)
at Microsoft.ApplicationServer.Caching.DataCacheFactory..ctor()
at DistributedInMemory.Program.Main(String[] args) in DistributedInMemory\Program.cs:line 16


知道为什么会发生此错误....谢谢。

【问题讨论】:

    标签: c# .net caching appfabric


    【解决方案1】:

    您需要将 configSections 元素紧跟在配置元素之后。

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <!-- Put config sections here -->
      <configSections>
        <!-- Put dataCache client section first -->
        <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" />
        <!-- Then other sections... -->
      </configSections>
    

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 2016-04-15
      • 2012-04-08
      • 2013-04-19
      • 2014-10-06
      • 1970-01-01
      相关资源
      最近更新 更多