C# Unrecognized configuration section system.serviceModel
Posted on 2008-11-19 13:36 YCOE 阅读(2853) 评论(0) 编辑 收藏 举报公司的项目,由于老项目里面使用的是.net framework 2.0环境,而我们开发使用的却是VS2008,所以在创建新的应用的时候,把环境设置为.net frameword2.0。
这是一个客户端界面程序,应用到web服务。
但在运行的时候出现以下错误:
Code
2008-11-18 18:36:44,093 [352] DEBUG UTrial.YHDClient.MainForm [(null)] <(null)> - System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.serviceModel. (D:\CMI\TMSEXE\YHDClient.exe.Config line 8)
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.ConfigurationManager.GetSection(String sectionName)
at System.Xml.Serialization.XmlSerializerCompilerParameters.Create(String location)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
at ***.CMIService.CMIClientService..ctor() in D:\CMI\TMSEXE\Web References\CMIService\Reference.cs:line 97
at ***.MainForm.Login() in D:\CMI\TMSEXE\form\MainForm.cs:line 67
2008-11-18 18:36:44,093 [352] DEBUG UTrial.YHDClient.MainForm [(null)] <(null)> - System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.serviceModel. (D:\CMI\TMSEXE\YHDClient.exe.Config line 8)
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.ConfigurationManager.GetSection(String sectionName)
at System.Xml.Serialization.XmlSerializerCompilerParameters.Create(String location)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
at ***.CMIService.CMIClientService..ctor() in D:\CMI\TMSEXE\Web References\CMIService\Reference.cs:line 97
at ***.MainForm.Login() in D:\CMI\TMSEXE\form\MainForm.cs:line 67
上网找了下,只要把配置文件中的一段注释掉就行了,见下面代码
配置文件如下:
Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="***.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<!--这一段要注释掉
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
-->
<applicationSettings>
<***.Properties.Settings>
<setting name="****"
serializeAs="String">
<value>http://www.****.com/***Service.asmx</value>
</setting>
</***.Properties.Settings>
</applicationSettings>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="***.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<!--这一段要注释掉
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
-->
<applicationSettings>
<***.Properties.Settings>
<setting name="****"
serializeAs="String">
<value>http://www.****.com/***Service.asmx</value>
</setting>
</***.Properties.Settings>
</applicationSettings>
</configuration>