Search code examples
c#configurationcustom-configuration

How to Configure App.config file in c#


I am using the Visual Studio 2005, and i created one application with "App.config" file. when i try to edit and add new value to that App.config file it shows an error please help me..

My app.config file contains:

<?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>

It shows an error as:

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"

Solution

  • Don't create a "MySettings" group. Put whatever you need in the AppSettings group.

    You COULD create a mySettings group, but if you do include custom (non-standard) configuration sections, you have to declare them in a configSections element as described here or here.

    I'd question if it's really necessary, however and go with my first answer unless there's a really good reason for adding custom sections, because it's just better to follow the normal standards. It just makes it easier on future maintenance programmers.