Skip to content

How to using config-parser without sections? #25

@byBenPuls

Description

@byBenPuls

Hello, dear developer.
My .cfg file does not contain sections (like [section]). How i can using libary?
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 Salaros.Configuration.ConfigParser.BackupCurrentLine(ConfigSection& currentSection, ConfigLine& currentLine, Int32 lineNumber)
   at Salaros.Configuration.ConfigParser.ReadKeyAndValue(ConfigSection& currentSection, ConfigLine& currentLine, String lineRaw, Int32 lineNumber, Boolean append, Boolean forceIncludeKey)
   at Salaros.Configuration.ConfigParser.Read(String configContent)
   at Salaros.Configuration.ConfigParser..ctor(String configFile, ConfigParserSettings settings)
   at Launcher_CS.Form1.Form1_Load(Object sender, EventArgs e) in line 43
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Control.CreateControl(Boolean ignoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

Code:

            var configFileFromPath = new ConfigParser(@"config.cfg",
                new ConfigParserSettings
                {
                    KeyValueSeparator = " ",
                    MultiLineValues = MultiLineValues.QuoteDelimitedValues
                    
                });
            
            string CsName = configFileFromPath.GetValue(null, "name"); // Error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions