admin管理员组

文章数量:1317906

I'm trying to make a program the saves value to ini file. Already imported Salaros.configparser, declare path with string and try to save some value after some dropdowm value with yes and no.

I follow this youtube tutorial:

Res.choice is a dropdown for screen resolution

private void btn_save_Click(object sender, EventArgs e)
{
    var setup_ini = new ConfigParser(setupini);

    if (this.Res_choice.Text == "1920x1080")
    {
        setup_ini.SetValue("TEST", "Value1", "Yes");
    }
    else
    {
        setup_ini.SetValue("TEST", "Value1", "No");
    }
}

Tried this and get error:

"Salaros.Configuration.ConfigParserException: 'This key value pair is orphan, all the keys must be preceded by a section.. On the line no. #2.'"

At first, I thought it was because the program can't find the header so I added it to the ini file and it still show the same error.

[TEST]
Value1=Yes

I'm trying to make a program the saves value to ini file. Already imported Salaros.configparser, declare path with string and try to save some value after some dropdowm value with yes and no.

I follow this youtube tutorial: https://www.youtube/watch?v=c7C54GlAvdI

Res.choice is a dropdown for screen resolution

private void btn_save_Click(object sender, EventArgs e)
{
    var setup_ini = new ConfigParser(setupini);

    if (this.Res_choice.Text == "1920x1080")
    {
        setup_ini.SetValue("TEST", "Value1", "Yes");
    }
    else
    {
        setup_ini.SetValue("TEST", "Value1", "No");
    }
}

Tried this and get error:

"Salaros.Configuration.ConfigParserException: 'This key value pair is orphan, all the keys must be preceded by a section.. On the line no. #2.'"

At first, I thought it was because the program can't find the header so I added it to the ini file and it still show the same error.

[TEST]
Value1=Yes
Share Improve this question asked Feb 22 at 4:43 Pavaris PobhirunPavaris Pobhirun 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Mentioned error happens when there is no section header like below.

Value1=Yes

Stack trace:

Unhandled exception. Salaros.Configuration.ConfigParserException: This key value pair is orphan, all the keys must be preceded by a section.. On the line no. #1.

   at Salaros.Configuration.ConfigParser.BackupCurrentLine(ConfigSection& currentSection, ConfigLine& currentLine, Int32 lineNumber)
   at Salaros.Configuration.ConfigParser.Read(String configContent)
   at Salaros.Configuration.ConfigParser..ctor(String configFile, ConfigParserSettings settings)
   at Program.<Main>$(String[] args) in ...

Adding a section header must fix the exception. Please make sure to save the file after adding the section header.

本文标签: