ConfigurationSection - 自定义部分未定义 - 为什么?
我正在尝试构建自定义配置,但由于某种原因,我无法让它工作。如果有人能看到我的问题出在哪里,我将不胜感激。
这是代码:
public class PointServices : ConfigurationSection
{
public static PointServices Get()
{
var t = ConfigurationManager.GetSection("point.Services/xServices") as PointServices;
return t;
}
//<summary>
//Declares a collection element represented in the following configuration sub-section
//<singleInstances> <add .../> </singleInstances>
//</summary>
[ConfigurationProperty("xServices", IsDefaultCollection = true)]
[ConfigurationCollection(typeof(PointServices))]
public PointServicesCollection Services
{
get
{
//var v = base["xServices"];
return (PointServicesCollection) base["xServices"];
}
}
}
public class PointService : ConfigurationElement
{
[ConfigurationProperty("name",IsRequired = true)]
public string Name
{
get
{
return this["name"].ToString();
}
}
[ConfigurationProperty("type", IsRequired = true)]
public string Type
{
get
{
return this["type"].ToString();
}
}
}
这是配置:
<sectionGroup name="point.Services">
<section name="xServices" type="XYZ.Messaging.PointServiceConfiguration.PointServices, XYZ.Point.Messaging" />
</sectionGroup>
...
<point.Services>
<xServices>
<xService>
<add name="XYZService" type="XYZService" />
</xService>
</xServices>
</point.Services>
当我运行时:PointServices.Get()
,我得到:
无法识别的元素“xService”。
我尝试将 xService 添加到部分定义中,如下所示: 但它似乎没有帮助。
如果有人有任何想法,请帮忙!谢谢
I'm trying to build a custom configuration and with some reason, I can't get it work. I'll appreciate if anyone can see where my problem is.
Here is the code:
public class PointServices : ConfigurationSection
{
public static PointServices Get()
{
var t = ConfigurationManager.GetSection("point.Services/xServices") as PointServices;
return t;
}
//<summary>
//Declares a collection element represented in the following configuration sub-section
//<singleInstances> <add .../> </singleInstances>
//</summary>
[ConfigurationProperty("xServices", IsDefaultCollection = true)]
[ConfigurationCollection(typeof(PointServices))]
public PointServicesCollection Services
{
get
{
//var v = base["xServices"];
return (PointServicesCollection) base["xServices"];
}
}
}
public class PointService : ConfigurationElement
{
[ConfigurationProperty("name",IsRequired = true)]
public string Name
{
get
{
return this["name"].ToString();
}
}
[ConfigurationProperty("type", IsRequired = true)]
public string Type
{
get
{
return this["type"].ToString();
}
}
}
and here is the config:
<sectionGroup name="point.Services">
<section name="xServices" type="XYZ.Messaging.PointServiceConfiguration.PointServices, XYZ.Point.Messaging" />
</sectionGroup>
...
<point.Services>
<xServices>
<xService>
<add name="XYZService" type="XYZService" />
</xService>
</xServices>
</point.Services>
When I'm running: PointServices.Get()
, I'm getting:
Unrecognized element 'xService'.
I tried to add xService to the section definition as following:<section name="xService" type="XYZPoint.Messaging.PointServiceConfiguration.PointService, Barcap.FIA.Point.Messaging" />
but it didn't seem to help.
If anyone has any idea, please help! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
并且您需要另一个 xService 说明符
And you need another specifier for xService
xServices 应该是一个sectionGroup,而不是一个section。并且xService应该被定义为一个部分。
xServices should be a sectionGroup, not a section. And xService should be defined as a section.