Coder Perfect

Initialization of the Configuration System Error

Problem

I’m not familiar with Visual Studio. Currently, I’m working on a Login form.

This code is mine.

string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
    using (OdbcConnection connect = new OdbcConnection(connectionString))
    {
        connect.Open();
        OdbcCommand cmd = new OdbcCommand("SELECT username, password FROM receptionist", connect);
        OdbcDataReader reader = cmd.ExecuteReader();

        if (username_login.Text == username && password_login.Text == password)
        {
            this.Hide();
            MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.Close();
        }
        else 
            MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        connect.Close();
    }
}
catch (OdbcException ex)
{
    MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

However, when I try to key in the login and password, I get an error message saying that the configuration system failed to initialize. I’m simply curious as to what kind of issue this is and how I might remedy it.

Please help.

Asked by sean

Solution #1

Make sure that your config file (web.config if web, or app.config if windows) in your project starts as:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" 
                      type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

            <section name="YourProjectName.Properties.Settings" 
                     type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                     requirePermission="false" />

        </sectionGroup>
    </configSections>
</configuration>

The configSections element must be the first child inside the configuration element.

Make sure to replace YourProjectName with the name of your project in the name attribute of the section element.

I had the same problem after creating a webservice in a class library project and then copying (overwriting) the config file (in order to bring the endpoints configuration) to my windows program. configSections had been accidentally removed.

Answered by feluco79

Solution #2

Try restarting your application after deleting outdated configuration files from c:UsersusernameAppDataLocalappname and c:UsersusernameAppDataRoamingappname.

Answered by jarek

Solution #3

The Error can also occur when Windows creates a duplicate in the registry.

Simply delete this folder and you’re done. Give it a shot.

Answered by Ashu Gupta

Solution #4

Make sure you’ve declared the section in the configSections> element if you’ve added your own custom configuration sections to your App.Config. I added my configuration XML but forgot to specify the configuration section at the top, which resulted in the error “Configuration system failed to initialize.”

Answered by Flash Gordon

Solution #5

After much searching, I discovered that this issue has an inner exception that tells you exactly what’s wrong with your configuration file.

Answered by Gerrie Pretorius

Post is based on https://stackoverflow.com/questions/6436157/configuration-system-failed-to-initialize