diff --git a/mcs/class/System/System.Configuration/SettingsPropertyValue.cs b/mcs/class/System/System.Configuration/SettingsPropertyValue.cs index 9bf62c0..9f026461 100644 --- a/mcs/class/System/System.Configuration/SettingsPropertyValue.cs +++ b/mcs/class/System/System.Configuration/SettingsPropertyValue.cs @@ -118,11 +118,18 @@ namespace System.Configuration #if (XML_DEP) case SettingsSerializeAs.Xml: if (propertyValue != null) { - XmlSerializer serializer = new XmlSerializer (propertyValue.GetType ()); - StringWriter w = new StringWriter(CultureInfo.InvariantCulture); - - serializer.Serialize (w, propertyValue); - serializedValue = w.ToString(); + using (StringWriter w = new StringWriter(CultureInfo.InvariantCulture)) + { + var xmlSettings = new XmlWriterSettings(); + xmlSettings.OmitXmlDeclaration = true; + using (var writer = XmlWriter.Create(w, xmlSettings)) + { + XmlSerializer serializer = new XmlSerializer(propertyValue.GetType ()); + var emptyNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); + serializer.Serialize(writer, propertyValue, emptyNamespaces); + } // writer.Flush happens here + serializedValue = w.ToString(); + } } else serializedValue = null;