关于c#:自定义配置部分的问题

Problems with custom config section

我正在尝试创建一个相当简单的自定义配置部分。我的班级是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
namespace NetCenterUserImport
{
    public class ExcludedUserList : ConfigurationSection
    {
        [ConfigurationProperty("name")]
        public string Name
        {
            get { return (string)base["name"]; }
        }

        [ConfigurationProperty("excludedUser")]
        public ExcludedUser ExcludedUser
        {
            get { return (ExcludedUser)base["excludedUser"]; }
        }

        [ConfigurationProperty("excludedUsers")]
        public ExcludedUserCollection ExcludedUsers
        {
            get { return (ExcludedUserCollection)base["excludedUsers"]; }
        }
   }

   [ConfigurationCollection(typeof(ExcludedUser), AddItemName ="add")]
   public class ExcludedUserCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ExcludedUserCollection();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ExcludedUser)element).UserName;
        }
    }

    public class ExcludedUser : ConfigurationElement
    {
        [ConfigurationProperty("name")]
        public string UserName
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }
    }
}

我的app.config是:

1
2
3
4
5
  <excludedUserList name="test">
<excludedUser name="Hello" />
<excludedUsers>
 
</excludedUsers>

当我尝试使用以下方法获取自定义配置节时:

2

我有个例外说

0

我肯定我遗漏了一些简单的东西,但我已经看了上面的十几个例子和答案,似乎找不到哪里出错了。


你是在excludedusercollection.createnewelement creating a method should be a en excludedusercollection审单元:such asP></

1
2
3
4
protected override ConfigurationElement CreateNewElement()
{
    return new ExcludedUser();
}

method for as changing the above挤压我。P></