File.CreateText encoding as UTF-8 in some environments but and UTF-8 with BOM in others

522 Views Asked by At

We are using the File.CreateText method which according to MSDN:

Creates or opens a file for writing UTF-8 encoded text. If the file already exists, its contents are overwritten.

(https://learn.microsoft.com/en-us/dotnet/api/system.io.file.createtext?view=netframework-4.5.2)

When we promote this code into other environments the output file is correctly encoded as UTF-8

But for one environment, the same method is producing a file encoded as UTF-8 ByteOrderMark and causing mayhem.

I understand the most direct fix should be to use StreamWriter and input UTF8Encoding(False) into the constructor

But I don't understand why using File.CreateText only causes an issue/creates UTF-8 with BOM in one specific environment and not the others

Can someone please help explain this to me?

0

There are 0 best solutions below