ConfigurationManager.GetSection throws exception: "The entry '____' has already been added"
ConfigurationManager.GetSection throws exception: "The entry '____' has already been added"
(OP)
I’m using
Here’s the config file:
I’ve seen this issue all over Google, but nothing that’s helped me solve the issue yet.
Thanks,
Eliezer
System.Configuration.ConfigurationManager.GetSection
to read a custom configuration section from an App.config. If I have two nodes that contain an identical value (such as the two “Station” nodes, below, with the identical highlighted values) – which is a project requirement – I get the error below when method GetSection is called.The entry 'C:\Local_folder_path_goes_here' has already been added.
Here’s the config file:
CODE --> XML
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="StationsSection" type="TV_EcFtpClient.StationConfigurationSection, TV_EcFtpClient"/> </configSections> <StationsSection> <Stations> <add FtpHostname ="ftp://upload.acmeCompany.com/" DestinationFolderPath="C:\Local_folder_path_goes_here" FtpFolderPath="acme_ftp/SourceFolder/" FtpUsername="fred" FtpPassword="fr3d$p@sswurd" FtpTimeoutInSeconds="30"/> <add FtpHostname ="ftp://upload.acmeCompany.com/" DestinationFolderPath="C:\Local_folder_path_goes_here" FtpFolderPath="acme_ftp/SourceFolder/" FtpUsername="fred" FtpPassword="fr3d$p@sswurd" FtpTimeoutInSeconds="30"/> </Stations> </StationsSection> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> </startup> <appSettings> <add key="NameOfService" value="ECClient"/> <add key="PollingFrequencyInSeconds" value="60"/> </appSettings> </configuration>
I’ve seen this issue all over Google, but nothing that’s helped me solve the issue yet.
Thanks,
Eliezer
RE: ConfigurationManager.GetSection throws exception: "The entry '____' has already been added"
CODE --> C#
returning the "DestinationFolderPath", so it was expected to be unique. Instead, I found a property that would actually be unique.
And if there wouldn't have been one property that would always be unique, I would have done a "composite key" approach to return as the key. For example: