Пытаюсь добавить пользовательский раздел конфигурации после другого поста здесь, но получаю сообщение об ошибке:
Произошло необработанное исключение типа «System.Configuration.ConfigurationErrorsException» в System.Configuration.dll.
Дополнительная информация: Нераспознанный элемент «Процессор».
в этой строке:
return (ProcessorsConfig)ConfigurationManager.GetSection("Processors") ?? new ProcessorsConfig();
вот мой код:
public class ProcessorsConfig : ConfigurationSection
{
public static ProcessorsConfig GetConfig()
{
return (ProcessorsConfig)ConfigurationManager.GetSection("Processors") ?? new ProcessorsConfig();
}
[ConfigurationProperty("Processors")]
[ConfigurationCollection(typeof(Processors), AddItemName = "Processor")]
public Processors Processors
{
get
{
object o = this["Processors"];
return o as Processors;
}
}
}
[ConfigurationCollection(typeof(Processor), AddItemName="Processor", CollectionType = ConfigurationElementCollectionType.BasicMap)]
public class Processors : ConfigurationElementCollection
{
public Processor this[int index]
{
get
{
return base.BaseGet(index) as Processor;
}
set
{
if (base.BaseGet(index) != null)
base.BaseRemoveAt(index);
this.BaseAdd(index, value);
}
}
public new Processor this[string responseString]
{
get { return (Processor)BaseGet(responseString); }
set
{
if (BaseGet(responseString)!=null)
BaseRemoveAt(BaseIndexOf(BaseGet(responseString)));
BaseAdd(value);
}
}
protected override ConfigurationElement CreateNewElement()
{
return new Processor();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((Processor)element).Name;
}
}
public class Processor : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired=true)]
public string Name
{
get
{
return this["name"] as string;
}
}
[ConfigurationProperty("searchPattern", IsRequired = true)]
public string SearchPattern
{
get
{
return this["searchPattern"] as string;
}
}
[ConfigurationProperty("collectionFolder", IsRequired = true)]
public string CollectionFolder
{
get
{
return this["collectionFolder"] as string;
}
}
[ConfigurationProperty("failureFolder", IsRequired = true)]
public string FailureFolder
{
get
{
return this["failureFolder"] as string;
}
}
[ConfigurationProperty("xmlOutputFolder", IsRequired = true)]
public string XMLOutputFolder
{
get
{
return this["xmlOutputFolder"] as string;
}
}
}
и мой app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Processors" type="Ideagen.PHE_PMEP_Processor_v2.Config.ProcessorsConfig, PHEPMEPProcessorv2"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<appSettings>
</appSettings>
<Processors>
<Processor name="test" collectionFolder="c:\temp\phev2\collection" searchPattern="*.txt" failureFolder="c:\temp\phev2\failure" xmlOutputFolder="c:\temp\phev2\xmlout"></Processor>
</Processors>
</configuration>
Любые подсказки?