Свойство Custom Config Section не является элементом конфигурации

Мне нужен еще один взгляд на эту проблему. Я получаю

ConfigurationErrorsException был необработанным. «Свойство« exportClientSettings »не является элементом ConfigurationElement».

Исключение возникает при вызове ExportClientConfiguration.GetSection();

Вот мой код:

App.config

   

Код C #

 ///  /// The export client configuration section. ///  public class ExportClientConfiguration : ConfigurationSection, IExportClientConfiguration { private const string ExportClientSettingsCollectionName = "exportClientSettings"; ///  /// Gets the export client configuration items. ///  ///  /// The export client configuration items. ///  [ConfigurationProperty(ExportClientSettingsCollectionName, IsDefaultCollection = true)] public IEnumerable ExportClientConfigurationItems { get { return base[ExportClientSettingsCollectionName] as ExportClientSettingsCollection; } } ///  /// Gets the export client path settings. ///  ///  /// The export client path settings. ///  public IList ExportClientSettings { get { return ExportClientConfigurationItems.ToList(); } } ///  /// Gets the section. ///  /// Name of the configuration section. /// The configuration section. public static IExportClientConfiguration GetSection(string configurationSectionName = "exportClientConfiguration") { IExportClientConfiguration section = ConfigurationManager.GetSection(configurationSectionName) as ExportClientConfiguration; return section; } } ///  /// An IEnumerable collection fo ExportClientSettings ///  [ConfigurationCollection(typeof(ExportClientSettings), AddItemName = "exportClientSetting")] public class ExportClientSettingsCollection : ConfigurationElementCollection, IEnumerable { ///  /// Gets the  at the specified index. ///  ///  /// The . ///  /// The index. ///  public ExportClientSettings this[int index] { get { return BaseGet(index) as ExportClientSettings; } } ///  /// Returns an enumerator that iterates through the collection. ///  ///  /// A  that can be used to iterate through the collection. ///  public new IEnumerator GetEnumerator() { return (from item in Enumerable.Range(0, Count) select this[item]).GetEnumerator(); } protected override ConfigurationElement CreateNewElement() { return new ExportClientSettings(); } protected override object GetElementKey(ConfigurationElement element) { var lConfigElement = element as ExportClientSettings; return lConfigElement != null ? lConfigElement.Name : null; } } ///  /// The export client path settings ///  public class ExportClientSettings : ConfigurationElement, IExportClientSettings { private const string NameProperty = "name"; private const string PathProperty = "path"; ///  /// Gets the name. ///  ///  /// The name to identify the export path and filename. ///  [ConfigurationProperty(NameProperty, IsKey = true)] public string Name { get { return this[NameProperty].ToString(); } } ///  /// Gets the path. ///  ///  /// The path. ///  [ConfigurationProperty(PathProperty)] public string Path { get { return this[PathProperty].ToString(); } } } 

Что мне не хватает?

Пара проблем.

  1. ExportClientConfigurationItems должно быть типа ExportClientSettingsCollection не IEnumerable .
  2. В вашем файле конфигурации Path имеет заглавные буквы, он должен быть маленькими буквами path=\\Example\Path" , так как вы украсили свойство ConfigurationProperty в нижнем регистре.

Фиксируя эти два, он работает.