C# 客户端配置文件中出现错误
我正在尝试创建一个AppFabric缓存客户端,它是一个控制台应用程序。但在创建DataCacheFactory的新实例时在客户端配置文件中收到错误。C# 客户端配置文件中出现错误,c#,.net,caching,appfabric,C#,.net,Caching,Appfabric,我正在尝试创建一个AppFabric缓存客户端,它是一个控制台应用程序。但在创建DataCacheFactory的新实例时在客户端配置文件中收到错误。连接设置在App.Config文件中提供,如中所述。 代码 } App.Config文件 例外 Microsoft.ApplicationServer.Caching.DataCacheException: 错误代码:子状态:客户端配置文件中出现错误。--> System.Configuration.ConfigurationErrorsExc
连接设置在App.Config文件中提供,如中所述。
代码 }
App.Config文件
例外
Microsoft.ApplicationServer.Caching.DataCacheException:
错误代码:子状态:客户端配置文件中出现错误。-->
System.Configuration.ConfigurationErrorsException:配置系统无法启动
初始化--->
System.Configuration.ConfigurationErrorsException:
每个配置文件只允许一个元素
如果存在,则必须是根元素的第一个子元素。
(DistributedMemory.vshost.exe.Config第7行)
在System.Configuration.ConfigurationSchemaErrors.Throwiferors(布尔ignoreLocal)
在
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
在System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()中
位于System.Configuration.ClientConfigurationSystem.EnsureInit(字符串configKey)
---内部异常堆栈跟踪的结束---
位于System.Configuration.ClientConfigurationSystem.EnsureInit(字符串configKey)
位于System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(字符串部分名称)
在
System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IIInternalConfigSystem.GetSection(字符串sectionName)
位于System.Configuration.ConfigurationManager.GetSection(字符串sectionName)
在Microsoft.ApplicationServer.Caching.ClientConfigReader..ctor()上
位于Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(字符串路径)
---内部异常堆栈跟踪的结束---
位于Microsoft.ApplicationServer.Caching.ConfigFile.ThroweException(Int32错误代码,异常e)
位于Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration.Initialize(字符串路径)
在Microsoft.ApplicationServer.Caching.DataCacheFactory..ctor()上
在DistributedMemory\Program.cs中的DistributedMemory.Program.Main(字符串[]args)处:第16行
知道为什么会发生此错误吗……谢谢。您需要将configSections元素放在configuration元素之后
<?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>
<?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
<?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>