Configuration System Failed to Initialize

2019-01-03 02:26发布

I'm new to Visual Studio. I'm currently creating a Login form.

I have this code.

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);
}

But whenever I try to type in the username and password there is an error called Configuration system failed to initialize. I'm just wondering what kind of problem is this and how could I solve this?

Please help.

19条回答
Lonely孤独者°
2楼-- · 2019-01-03 03:22

Wow it took me forever to figure out this one. For some reason changing the attribute [assembly: AssemblyCompany("CompanyName")] at AssemblyInfo.cs made this error disappear. I was referencing a project that had a different value for the attribute [assembly: AssemblyCompany("CompanyName")]. I maked sure both projects had the same attribute value and it worked great!

查看更多
Juvenile、少年°
3楼-- · 2019-01-03 03:23

If you've added your own custom configuration sections to your App.Config, make sure you have defined the section in the <configSections> element. I added the my config XML but forgot to declare the configuration section up top - which caused the exception "Configuration system failed to initialize" for me.

查看更多
小情绪 Triste *
4楼-- · 2019-01-03 03:23

In my case the only solution was to add the reference to the System.Configuration in my Test project as well.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-03 03:23

I too faced the same problem, But accidentally i written the without writting the ,the previous one should go inside this tags. thus the 'Configuration System Failed to Initialize' error was arising. Hope it will help

查看更多
ら.Afraid
6楼-- · 2019-01-03 03:23

In My case, I have two configsections in the app.config file. After deleting the one hiding in the code lines, the app works fine.

So for someone has the same issue, check if you have duplicate configsections first.

查看更多
仙女界的扛把子
7楼-- · 2019-01-03 03:24

If you have User scoped settings you may also have a user.config file somewhere in the [Userfolder]\AppData\Local[ProjectName] folder.

If you later remove the User scoped settings the user.config will not automatically be removed, and it's presence may cause the same error message. Deleting the folder did the trick for me.

查看更多
登录 后发表回答