Can anyone explain the difference between calling GetPreamble() on a newly instantiated utf8 encoding as opposed to the public ones available from the Encoding class?
byte[] p1 = Encoding.UTF8.GetPreamble();
byte[] p2 = new UTF8Encoding().GetPreamble();
p1 is the normal 3 byte utf-8 preamble, but p2 ends up being empty, which seems very wrong.
The difference is that the UTF8 property of Enconding is created this way
this indicates that encoderShouldEmitUTF8Identifier = true so the 3 byte preamble is there
and your call to the default constructor
that is equivalent to
To get same results: