×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ConfigurationManager.GetSection throws exception: "The entry '____' has already been added"

ConfigurationManager.GetSection throws exception: "The entry '____' has already been added"

ConfigurationManager.GetSection throws exception: "The entry '____' has already been added"

(OP)
I’m using
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"

(OP)
I found the problem. I had the method

CODE --> C#

protected override object GetElementKey(ConfigurationElement element) 

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:
return station.FtpHostname + station.DestinationFolderPath + station.FtpFolderPath + station.FtpUsername;

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close