Fix: XmlWriterSettings.Encoding must be registered in static Encoding (#56164)
authorKrzysztof Wicher <kwicher@microsoft.com>
Fri, 23 Jul 2021 13:28:13 +0000 (15:28 +0200)
committerGitHub <noreply@github.com>
Fri, 23 Jul 2021 13:28:13 +0000 (15:28 +0200)
* Fix: XmlWriterSettings.Encoding must be registered in static Encoding

* Update src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs

Co-authored-by: Buyaa Namnan <bunamnan@microsoft.com>
Co-authored-by: Buyaa Namnan <bunamnan@microsoft.com>
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs

index 91a9b6d..038222f 100644 (file)
@@ -160,11 +160,8 @@ namespace System.Xml
             // grab bom before possibly changing encoding settings
             ReadOnlySpan<byte> bom = _encoding.Preamble;
 
-            // the encoding instance this creates can differ from the one passed in
-            this._encoding = Encoding.GetEncoding(
-                settings.Encoding.CodePage,
-                _charEntityFallback,
-                settings.Encoding.DecoderFallback);
+            _encoding = (Encoding)settings.Encoding.Clone();
+            _encoding.EncoderFallback = _charEntityFallback;
 
             _encoder = _encoding.GetEncoder();