@@ -59,6 +59,7 @@ public class XmlSerializer
59
59
private XmlMapping _mapping ;
60
60
private XmlDeserializationEvents _events = new XmlDeserializationEvents ( ) ;
61
61
#if NET_NATIVE
62
+ public string DefaultNamespace = null ;
62
63
private XmlSerializer innerSerializer ;
63
64
private readonly Type rootType ;
64
65
#endif
@@ -156,13 +157,7 @@ public XmlSerializer(Type type, string defaultNamespace)
156
157
throw new ArgumentNullException ( "type" ) ;
157
158
158
159
#if NET_NATIVE
159
- // The ctor is not supported, but we cannot throw PNSE unconditionally
160
- // because the ctor is used by ctor(Type) which passes in a null defaultNamespace.
161
- if ( ! string . IsNullOrEmpty ( defaultNamespace ) )
162
- {
163
- throw new PlatformNotSupportedException ( ) ;
164
- }
165
-
160
+ this . DefaultNamespace = defaultNamespace ;
166
161
rootType = type ;
167
162
#endif
168
163
_mapping = GetKnownMapping ( type , defaultNamespace ) ;
@@ -344,6 +339,11 @@ internal void Serialize(XmlWriter xmlWriter, object o, XmlSerializerNamespaces n
344
339
throw new InvalidOperationException ( SR . Format ( SR . Xml_MissingSerializationCodeException , this . rootType , typeof ( XmlSerializer ) . Name ) ) ;
345
340
}
346
341
342
+ if ( ! string . IsNullOrEmpty ( this . DefaultNamespace ) )
343
+ {
344
+ this . innerSerializer . DefaultNamespace = this . DefaultNamespace ;
345
+ }
346
+
347
347
XmlSerializationWriter writer = this . innerSerializer . CreateWriter ( ) ;
348
348
writer . Init ( xmlWriter , namespaces == null || namespaces . Count == 0 ? DefaultNamespaces : namespaces , encodingStyle , id ) ;
349
349
try
@@ -459,6 +459,11 @@ internal object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeseri
459
459
throw new InvalidOperationException ( SR . Format ( SR . Xml_MissingSerializationCodeException , this . rootType , typeof ( XmlSerializer ) . Name ) ) ;
460
460
}
461
461
462
+ if ( ! string . IsNullOrEmpty ( this . DefaultNamespace ) )
463
+ {
464
+ this . innerSerializer . DefaultNamespace = this . DefaultNamespace ;
465
+ }
466
+
462
467
XmlSerializationReader reader = this . innerSerializer . CreateReader ( ) ;
463
468
reader . Init ( xmlReader , encodingStyle ) ;
464
469
try
0 commit comments