diff --git a/src/ConfigParser.cs b/src/ConfigParser.cs index 2bd2c96..5fb1a1b 100644 --- a/src/ConfigParser.cs +++ b/src/ConfigParser.cs @@ -422,7 +422,8 @@ public bool SetValue(string sectionName, string keyName, string value) if (!sections.TryGetValue(sectionName, out var section)) { - section = new ConfigSection(sectionName, Lines.Max(l => l.LineNumber)); + var lineNumber = (null != Lines && Lines.Any()) ? Lines.Max(l => l.LineNumber) : -1; + section = new ConfigSection(sectionName, lineNumber); sections.Add(sectionName, section); }