Make Encoding.Default return UTF8 without BOM emission (#10747)
authorTarek Mahmoud Sayed <tarekms@microsoft.com>
Thu, 6 Apr 2017 19:58:17 +0000 (12:58 -0700)
committerGitHub <noreply@github.com>
Thu, 6 Apr 2017 19:58:17 +0000 (12:58 -0700)
* Make Encoding.Default return UTF8 without BOM emission

* Remove SL reference in the code

* Remove the static cache

src/mscorlib/src/System/Text/Encoding.cs
src/mscorlib/src/System/Text/UTF8Encoding.cs

index a4fdc79..aab9b4a 100644 (file)
@@ -1230,10 +1230,8 @@ namespace System.Text
 
             Encoding enc;
 
-
-            // For silverlight we use UTF8 since ANSI isn't available
-            enc = UTF8;
-
+            // For netcore we use UTF8 since ANSI isn't available
+            enc = new UTF8Encoding.UTF8EncodingSealed(encoderShouldEmitUTF8Identifier: false);
 
             // This method should only ever return one Encoding instance
             return Interlocked.CompareExchange(ref defaultEncoding, enc, null) ?? enc;
index d321c7c..078fb46 100644 (file)
@@ -58,6 +58,7 @@ namespace System.Text
         internal sealed class UTF8EncodingSealed : UTF8Encoding
         {
             public UTF8EncodingSealed() : base(encoderShouldEmitUTF8Identifier: true) { }
+            public UTF8EncodingSealed(bool encoderShouldEmitUTF8Identifier) : base(encoderShouldEmitUTF8Identifier) { }
         }
 
         // Used by Encoding.UTF8 for lazy initialization