如何在c#中配置App.config文件

Ram*_*esh 2 c# configuration custom-configuration

我正在使用Visual Studio 2005,并使用"App.config"文件创建了一个应用程序.当我尝试编辑并向该App.config文件添加新值时,它显示错误请帮助我..

我的app.config文件包含:

<?xml version="1.0" encoding="utf-8" ?>
 <configuration>
  <appSettings>
   <add key="keyvalue" value="value"/>
    <add key="keyvalue1" value="value1"/>
 </appSettings>
 <mySettings>
   <add name="myname" myvalue="value1"/>
 </mySettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

它显示错误:

Could not find schema information for the element "mySettings"
Could not find schema information for the element "add"
Could not find schema information for the element "myvalue"
Run Code Online (Sandbox Code Playgroud)

Dav*_*vid 6

不要创建"MySettings"组.在AppSettings组中放置您需要的任何内容.

您可以创建一个mySettings组,但如果您确实包含自定义(非标准)配置部分,则必须按照此处此处所述 configSections元素中声明它们.

我会质疑它是否真的有必要,但是除非有一个非常好的理由添加自定义部分,否则请继续我的第一个答案,因为它更好地遵循正常标准.它只是使未来的维护程序员更容易.