I know that this post has 3 years old, but this could help future developers when they find this kind of problem.
After a little of research, I found out that the string encoding in .net is UTF-16.
"It depends where the string 'came from'. A .NET string is Unicode (UTF-16). The only way it could be different if you, say, read the data from a database into a byte array.".
So, my suspicion is that if you have an environment that has a preset configuration of an encoder that doesn't support those kinds of characters, for example, Encoding.Unicode, it will show a messy string:
public static void Main()
{
string testString = "Sedán";
Console.WriteLine(Utf16ToUnicode(testString));
}
public static string Utf16ToUnicode(string utf16String)
{
// Get UTF16 bytes and convert UTF16 bytes to UNICODE bytes
byte[] utf16Bytes = Encoding.Unicode.GetBytes(utf16String);
byte[] unicodeBytes = Encoding.Convert(Encoding.Unicode, Encoding.Unicode, utf16Bytes);
// Return UNICODE bytes as ANSI string
return Encoding.Default.GetString(unicodeBytes);
}
The output: Sed�n
I had a similar problem. My docker container was running under a Debian 10 image and according with this article, does not have default locale set. I don't know which implications this could lead to, but in my case the "replacement character" shows when I try to render a currency unit if the encoding string is UTF-16. So to solve this problem I used the resource manage from .NET in order to obtain the value as UTF-8(Note: I could programmatically transform the UTF-16 to UTF-8, as I show in the code example above, but its a high cost operation).