Skip to content

Changing console's OutputEncoding on linux to unicode generates garbage #29735

Description

@JustArchi

Hello.

I've experimented a bit in my cross-platform app by declaring Console.OutputEncoding = Encoding.Unicode; globally before first console entry gets written.

On Windows, as expected, the output encoding is changed nicely and the console displays whole range of symbols, including cyrillic characters.

On Linux, the encoding is also changed, but the console generates garbage from this point onwards, where previously the cyrillic characters would also show properly (probably due to UTF-8 already being default there).

Judging by my own research based on this line, I'd expect that changing encoding on linux would truly be a no-op operation which doesn't affect anything, or at worst produces an exception to handle during runtime, but instead it broke display that worked previously.

I'm not sure if this is intended or not, I apologize in advance if it is but I couldn't find any issue that relates to my problem. Feel free to close it in this case.

Otherwise, feel free to check the issue yourself, it should be enough to launch code similar to below on any linux machine:

Console.OutputEncoding = Encoding.Unicode;
Console.WriteLine("привет");

In my case, it prints ?@825B. It's important to test it with cyrillic or something more obscure, as 00 in ASCII characters and similar will be written as NULLs on the terminal, thus not displayed.

As you can expect, this issue also affects OS X.

Thank you in advance for looking into this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions