<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />

NameValueFileSectionHandler

using System.Configuration.Internal; using System.IO; using System.Xml; namespace System.Configuration { public class NameValueFileSectionHandler : IConfigurationSectionHandler { public object Create(object parent, object configContext, XmlNode section) { XmlNode xmlNode = section.Attributes.RemoveNamedItem("file"); object obj = NameValueSectionHandler.CreateStatic(parent, section); if (xmlNode != null && xmlNode.Value.Length != 0) { string text = null; text = xmlNode.Value; IConfigErrorInfo configErrorInfo = xmlNode as IConfigErrorInfo; if (configErrorInfo == null) return null; string filename = configErrorInfo.Filename; string directoryName = Path.GetDirectoryName(filename); string text2 = Path.Combine(directoryName, text); if (File.Exists(text2)) { ConfigXmlDocument configXmlDocument = new ConfigXmlDocument(); try { configXmlDocument.Load(text2); } catch (XmlException ex) { throw new ConfigurationErrorsException(ex.Message, ex, text2, ex.LineNumber); } if (section.Name != configXmlDocument.DocumentElement.Name) throw new ConfigurationErrorsException(string.Format(System.SR.Config_name_value_file_section_file_invalid_root, section.Name), configXmlDocument.DocumentElement); obj = NameValueSectionHandler.CreateStatic(obj, configXmlDocument.DocumentElement); } } return obj; } } }