System.Configuration.ConfigurationErrorsException: The element may only appear once in this section

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi guys!


When i am creating a customized *.config file and duplicate a dominio
section, it doesnt work:
<div style="background-color:white; color:black
<pre><span style="color:blue <div style="background-color:white; color:black <pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue utf-8<span style="color:black " <span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 configuration<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 configSections<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 section <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue dominios<span style="color:black " <span style="color:red type<span style="color:blue =<span style="color:black "<span style="color:blue Projeto.Pasta.Dominios, Projeto.Pasta<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 configSections<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 dominios<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 dominio <span style="color:red nome<span style="color:blue =<span style="color:black "<span style="color:blue DOMINIO1<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red chave<span style="color:blue =<span style="color:black "<span style="color:blue chave1<span style="color:black " <span style="color:red filtro<span style="color:blue =<span style="color:black "<span style="color:blue xxxxxxxxxxxxxxx<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red chave<span style="color:blue =<span style="color:black "<span style="color:blue chave2<span style="color:black " <span style="color:red filtro<span style="color:blue =<span style="color:black "<span style="color:blue xxxxxxxxxxxxxxx<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 dominio<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 dominio <span style="color:red nome<span style="color:blue =<span style="color:black "<span style="color:blue DOMINIO2<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add <span style="color:red chave<span style="color:blue =<span style="color:black "<span style="color:blue chave1<span style="color:black " <span style="color:red filtro<span style="color:blue =<span style="color:black "<span style="color:blue xxxxxxxxxxxxxxx<span style="color:black "<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add <span style="color:red chave<span style="color:blue =<span style="color:black "<span style="color:blue chave2<span style="color:black " <span style="color:red filtro<span style="color:blue =<span style="color:black "<span style="color:blue xxxxxxxxxxxxxxx<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 dominio<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 dominios<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configuration<span style="color:blue >
[/code]

[/code]

When i just have one domÃnio section, it works.

The *.cs code is this:

<div style="background-color:white; color:black
<pre><span style="color:blue <span style="color:blue using<span style="color:#000000 System.Configuration;

<span style="color:blue namespace<span style="color:#000000 Projeto.Pasta
{
<span style="color:blue public<span style="color:#000000 <span style="color:blue sealed<span style="color:#000000 <span style="color:blue class<span style="color:#000000 Dominios : ConfigurationSection
{
[ConfigurationProperty(<span style="color:#a31515 "dominio"<span style="color:#000000 )]
<span style="color:blue public<span style="color:#000000 FiltroAdCollection Dominio
{
<span style="color:blue get
<span style="color:#000000 {
<span style="color:blue return<span style="color:#000000 <span style="color:blue this<span style="color:#000000 [<span style="color:#a31515 "dominio"<span style="color:#000000 ] <span style="color:blue as<span style="color:#000000 FiltroAdCollection;
}
}
}
}

<span style="color:blue using<span style="color:#000000 System;
<span style="color:blue using<span style="color:#000000 System.Configuration;

<span style="color:blue namespace<span style="color:#000000 Projeto.Pasta
{

<span style="color:blue public<span style="color:#000000 <span style="color:blue sealed<span style="color:#000000 <span style="color:blue class<span style="color:#000000 FiltroAdCollection : ConfigurationElementCollection
{
<span style="color:blue readonly<span style="color:#000000 ConfigurationProperty _nome;

<span style="color:blue public<span style="color:#000000 FiltroAdCollection()
{
_nome = <span style="color:blue new<span style="color:#000000 ConfigurationProperty(<span style="color:#a31515 "nome"<span style="color:#000000 , <span style="color:blue typeof<span style="color:#000000 (<span style="color:blue string<span style="color:#000000 ));

Properties.Add(_nome);
}

<span style="color:blue public<span style="color:#000000 <span style="color:blue string<span style="color:#000000 Nome
{
<span style="color:blue get<span style="color:#000000 { <span style="color:blue return<span style="color:#000000 (String)<span style="color:blue this<span style="color:#000000 [_nome]; }
}


<span style="color:blue public<span style="color:#000000 FiltrosAd <span style="color:blue this<span style="color:#000000 [<span style="color:blue int<span style="color:#000000 index]
{
<span style="color:blue get
<span style="color:#000000 {
<span style="color:blue return<span style="color:#000000 <span style="color:blue base<span style="color:#000000 .BaseGet(index) <span style="color:blue as<span style="color:#000000 FiltrosAd;
}
<span style="color:blue set
<span style="color:#000000 {
<span style="color:blue if<span style="color:#000000 (<span style="color:blue base<span style="color:#000000 .BaseGet(index) != <span style="color:blue null<span style="color:#000000 )
{
<span style="color:blue base<span style="color:#000000 .BaseRemoveAt(index);
}
<span style="color:blue this<span style="color:#000000 .BaseAdd(index, value);
}
}

<span style="color:blue protected<span style="color:#000000 <span style="color:blue override<span style="color:#000000 ConfigurationElement CreateNewElement()
{
<span style="color:blue return<span style="color:#000000 <span style="color:blue new<span style="color:#000000 FiltrosAd();
}

<span style="color:blue protected<span style="color:#000000 <span style="color:blue override<span style="color:#000000 <span style="color:blue object<span style="color:#000000 GetElementKey(ConfigurationElement element)
{
<span style="color:blue return<span style="color:#000000 ((FiltrosAd)element).Chave;
}
}
}
<span style="color:blue using<span style="color:#000000 System.Configuration;

<span style="color:blue namespace<span style="color:#000000 Projeto.Pasta
{
<span style="color:blue public<span style="color:#000000 <span style="color:blue class<span style="color:#000000 FiltrosAd : ConfigurationElement
{
[ConfigurationProperty(<span style="color:#a31515 "chave"<span style="color:#000000 , IsRequired = <span style="color:blue true<span style="color:#000000 )]
<span style="color:blue public<span style="color:#000000 <span style="color:blue string<span style="color:#000000 Chave
{
<span style="color:blue get
<span style="color:#000000 {
<span style="color:blue return<span style="color:#000000 <span style="color:blue this<span style="color:#000000 [<span style="color:#a31515 "chave"<span style="color:#000000 ] <span style="color:blue as<span style="color:#000000 <span style="color:blue string<span style="color:#000000 ;
}
}

[ConfigurationProperty(<span style="color:#a31515 "filtro"<span style="color:#000000 , IsRequired = <span style="color:blue true<span style="color:#000000 )]
<span style="color:blue public<span style="color:#000000 <span style="color:blue string<span style="color:#000000 Filtro
{
<span style="color:blue get
<span style="color:#000000 {
<span style="color:blue return<span style="color:#000000 <span style="color:blue this<span style="color:#000000 [<span style="color:#a31515 "filtro"<span style="color:#000000 ] <span style="color:blue as<span style="color:#000000 <span style="color:blue string<span style="color:#000000 ;
}
}
}
}

Somebody can help me?[/code]


Thanks,
Anderson Olympio

View the full article
 
Back
Top