Several identical custom configurations in app.config

I am trying to create a custom configuration section in the app.config file of my C # .NET console application. It stores some information about some servers, for example:

<configSections>
  <sectionGroup name="serverGroup">
    <section name="server" type="RPInstaller.ServerConfig" allowLocation="true" allowDefinition="Everywhere"/>
  </sectionGroup>
</configSections>
<serverGroup>
  <server>
    <name>rmso2srvm</name>
    <isBatchServer>false</isBatchServer>
  </server>
  <server>
    <name>rmsb2srvm</name>
    <isBatchServer>true</isBatchServer>
  </server>
</serverGroup>

I have a class defined for a server section as follows:

namespace RPInstaller
{
    public class ServerConfig : ConfigurationSection
    {
        [ConfigurationProperty("name", IsRequired=true)]
        public string Name {...}

        [ConfigurationProperty("isBatchServer", IsRequired = true)]
        public bool IsBatchServer {...}
    }
}

When I try to load server partitions, I get an exception: "Partitions should appear only once in the configuration file."

How can I legally define multiple server partitions in the app.config file?

+3
source share
2 answers
<confgisections>
    <section name="server" type="RPInstaller.ServerConfig" allowLocation="true" allowDefinition="Everywhere"/>
</confgisections>
<server>
  <servers>
    </clear>
    <add name="rmso2srvm" isBatchServer="false"/>
    <add name="rmsb2srvm" isBatchServer="true"/>
  </servers>
</server>

As I previously set up the user section

VB code for access:

 Dim cfg As ServerSection = (ConfigurationManager.GetSection("Server"),ServerSection)
 cfg.ServersCollection("nameOfServer").isBatchServer
+2
source

web.config. . web.config - , - .


: "" - ConfigurationSection. , rmso2srvm

ServerElement : ConfigurationElement :

namespace RPInstaller
{
  public class ServerConfig : ConfigurationSection 
  {
    public class ServerElement : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired=true)]
        public string Name {...}
        [ConfigurationProperty("isBatchServer", IsRequired = true)]
        public bool IsBatchServer {...}  
    }
  }
}

: http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

0

All Articles