Well I think I found a good solution for this issue. It passes by serializing the sections instead of the Configuration object itself.
So, to ensure all the sections I need get Serialized/Deserialized together I've wrapped them all in one ConfigurationSectionGroup. I does the job, and allows me to export and import settings trough a WCF service, or directly on file.
Here's the code I used:
A configuration section base class:
public abstract class ConfigurationSectionBase : ConfigurationSection
{
public string Serialize()
{
return SerializeSection(null, Name, ConfigurationSaveMode.Minimal);
}
public void Deserialize(string configuration)
{
XmlReader reader = XmlReader.Create(new StringReader(configuration));
if (!reader.ReadToFollowing(Name)) return;
StringBuilder stringBuilder = new StringBuilder().Append(reader.ReadOuterXml());
var stringReader = new StringReader(stringBuilder.ToString());
reader = XmlReader.Create(stringReader);
DeserializeSection(reader);
}
}
Hope it helps someone...
Regards