Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C“配置部分”;每个配置文件只能显示一次节。”;_C#_Configsection - Fatal编程技术网

C# C“配置部分”;每个配置文件只能显示一次节。”;

C# C“配置部分”;每个配置文件只能显示一次节。”;,c#,configsection,C#,Configsection,我想创建一个包含许多clientUser <configuration> <configSections> <sectionGroup name="clientUsers"> <section name="clientUser" type="System.Configuration.NameValueFileSectionHandler" /> </sectio

我想创建一个包含许多
clientUser

 <configuration>
        <configSections>
          <sectionGroup name="clientUsers">
            <section name="clientUser" type="System.Configuration.NameValueFileSectionHandler" />
          </sectionGroup>
        </configSections>

        <clientUsers>
            <!-- user number 1  -->
            <clientUser>
              <add key="id"       value="1" />
              <add key="userName" value="someuser" />
              <add key="password" value="test" />
              <add key="IPs"      value="1,2,3" />
            </clientUser>

            <!-- user number 2  -->
            <clientUser>
              <add key="id"       value="2" />
              <add key="userName" value="avi2" />
              <add key="password" value="test" />
              <add key="IPs"      value="1,2,3" />
            </clientUser>
   </clientUsers>

为什么会出现此错误:

每个配置文件只能显示一次节。有关例外情况,请参阅帮助主题


如何创建
客户端用户列表

我想您正在System.Configuration MSDN链接下查找ConfigurationElementCollection类

还有一个家庭教师

codeproject站点中的一个简短片段

public class ShiSettingCollection : ConfigurationElementCollection
   {
      public ShiSettingElements this[int index]
      {
         get
         {
            return base.BaseGet(index) as ShiSettingElements;
         }
         set
         {
            if (base.BaseGet(index) != null)
            {
               base.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
         }
      }
      protected override System.Configuration.ConfigurationElement CreateNewElement()
      {
         return new ShiSettingElements();
      }

      protected override object GetElementKey(ConfigurationElement element)
      {
         return ((ShiSettingElements)element).Key;
      }
   }

XML中的注释实际上是这样写在文件中的?如果是,请更改//因为您得到的错误正是它所说的原因。ClientUser只允许在文件中出现一次。@Ramhound-你知道你的评论有多烦人吗???我在问如何创建ClientUser列表。我想已经有类似的问题了。检查对的答案。他是用一个自定义的配置处理程序来完成的。谢谢,但它不一样。。。看我的结构,它是不同的。谢谢