【发布时间】:2010-02-24 08:10:56
【问题描述】:
注意:这与SO question 非常相似,但我需要更多帮助。
我正在尝试在我的 .config 文件中创建以下部分,但在尝试访问此部分时出现异常。
.config 文件
<configSections>
<section name="foos" type="Ackbar.Mvc.Models.Foo.FooCollection, Ackbar.Mvc" requirePermission="false"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false" />
</configSections>
<foos>
<add name="aaa" something="zzz"/>
<add name="bbb" something="yyy"/>
<add name="ccc" something="xxx"/>
</foos>
好的,所以这意味着我需要创建两个类
类
public class FooCollection : ConfigurationElementCollection
{
... with my custom overrides, etc. ...
}
和
public class FooElement : ConfigurationElement
{
[ConfigurationProperty("Name", IsRequired = true)]
public string Name { .. }
[ConfigurationProperty("Something ", IsRequired = true)]
public string Something { .. }
[ConfigurationProperty("IsDefault ", IsRequired = false, DefaultValue = false)]
public bool IsDefault { .. }
}
科尔。现在,当我执行以下操作时......
var whatever = ConfigurationManager.GetSection("foos") 抛出以下异常:-
创建时出错 配置节处理程序 foos:类型 'Ackbar.Mvc.Models.Foos.FooCollection' 不继承自 'System.Configuration.IConfigurationSectionHandler'。
有人可以帮帮我吗?我不想将集合包装在父部分中。
干杯:)
【问题讨论】:
标签: .net configuration configurationelement