我想建立一个自定义的配置,并有一些原因,我无法得到它的工作。如果有人能看到我的问题在哪里,我将不胜感激。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的添加到段定义如下: <section name="xService" type="XYZPoint.Messaging.PointServiceConfiguration.PointService, Barcap.FIA.Point.Messaging" />
,但它似乎并没有帮助。
如果有人有任何想法,请帮助!谢谢
伟大的,它有助于解决一个问题,但现在我有这个问题: http://stackoverflow.com/questions/1768362/sections-must-only-appear-once-per-config-file-why – 2009-11-20 04:35:40