I think you will need to override the OnDeserializeUnrecognizedElement . Please take a look at this answer.
Using the above approach, here is how I was able to achieve the result for your requirement:-
My SomeConfigSection class looks like this:-
public class SomeConfigSection : ConfigurationSection
{
[ConfigurationProperty("SomeConfig", IsRequired = true)]
public string SomeConfig
{
get { return (string)base["SomeConfig"]; }
set { base["SomeConfig"] = value; }
}
XElement _SomeParam;
public XElement SomeParam
{
get { return _SomeParam; }
}
protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
{
if (elementName == "SomeParam")
{
_SomeParam = (XElement)XElement.ReadFrom(reader);
return true;
}
else
return base.OnDeserializeUnrecognizedElement(elementName, reader);
}
}
My App.config looks like this:-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="SomeConfig" type="ConfigTest.SomeConfigSection,ConfigTest" />
</configSections>
<SomeConfig>
<SomeParam>SomeText</SomeParam>
</SomeConfig>
</configuration>
In my form, below is how I read the value :-
SomeConfigSection configSection = ConfigurationManager.GetSection("SomeConfig") as SomeConfigSection;
if (configSection != null)
label1.Text= configSection.SomeParam.Value;
Hope This Helps!