views:

92

answers:

2

Hi,

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

A: 

xServices should be a sectionGroup, not a section. And xService should be defined as a section.

Ken Mason
thanks for you help. do you know what do i get this:http://stackoverflow.com/questions/1768362/sections-must-only-appear-once-per-config-file-why
Or A
+1  A: 

And you need another specifier for xService

<sectionGroup name="point.Services">          
  <sectionGroup name="xServices">          
    <section name="xService" 
      type="XYZ.Messaging.PointServiceConfiguration.PointServices, XYZ.Point.Messaging" />  
  </sectionGroup name="xServices">         
</sectionGroup>
Charles Bretana
great, it help to fix one problem, but now i have this issue:http://stackoverflow.com/questions/1768362/sections-must-only-appear-once-per-config-file-why
Or A