internal void SetRawXml(ConfigurationSection configSection, string xmlElement) {
// Null or empty is equivalent to RevertToParent().
if (string.IsNullOrEmpty(xmlElement)) {
RevertToParent(configSection);
return;
}
ValidateSectionXml(xmlElement, configSection.SectionInformation.Name);
// Reset the ConfigurationSection with the XML.
ConfigurationSection parentConfigSection = FindImmediateParentSection(configSection);
ConfigXmlReader reader = new ConfigXmlReader(xmlElement, null, 0);
// Store the raw XML.
configSection.SectionInformation.RawXml = xmlElement;
// Update the section with the xml
try {
try {
bool wasPresent = configSection.ElementPresent;
PropertySourceInfo saveInfo = configSection.ElementInformation.PropertyInfoInternal();
configSection.Reset(parentConfigSection);
configSection.DeserializeSection(reader);
configSection.ResetModified();
configSection.ElementPresent = wasPresent;
configSection.ElementInformation.ChangeSourceAndLineNumber(saveInfo);
}
catch {
configSection.SectionInformation.RawXml = null;
throw;
}
}
catch (Exception e) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, configSection.SectionInformation.SectionName),
e, null, 0);
}
catch {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, configSection.SectionInformation.SectionName),
null, null, 0);
}
// Ignore previous attempts to remove the section.
configSection.SectionInformation.Removed = false;
}