summaryrefslogtreecommitdiff
blob: 3d60923d9714e3f497050f69354081c9d23351b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;