-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect Encoding in Console Output with WinExe OutputType #111057
Comments
Why are you asking for console when you explicitly disabled console by using |
Not having a visible output window is not the same as not having output altogether.
There are then many ways for an The general issue here looks to be that The general console environment on Windows has changed a lot over recent years, while I expect its something that could be fixed, but which is not a trivial task and which has a high chance of impacting existing Windows console applications. -- Some of these nuances also show up on Linux, since the Linux environment for console/terminal handling is a bit different and doesn't "cleanly" map onto what .NET had exposed (which was largely oriented around the Windows APIs from 25 years ago). |
Assigned to @tannergooding to finish triaging this |
@jkotas would you happen to have any context as to why we're simply passing The code was last touched back in 2016 (7b440e3) but much of it comes from .NET Framework and it doesn't appear as though the original authors are still on the team. There appear to be various mismatches in the paths between what the current encoding is expected to be vs what it actually might be. For example, This seems fixable, but also risky due to the code having been setup this way for so long. |
I do not have context why it is done this way. It has been like that since .NET Framework 1.0: https://github.com/SSCLI/sscli_20021101/blob/77d46e0f04f52052a12ac40ce2cf96712c934b3c/clr/src/bcl/system/console.cs#L150 It is quite possible that the (accidental) fallback to CP_ACP when there is no console attached was considered the right behavior back in 2001 when .NET Framework 1.0 shipped. CP_ACP was the default encoding to use across Windows back then.
What do you think the fix should be? Fallback to UTF-8? I do not see a problem with doing that. |
This was my initial thought, changing it to fallback to UTF-8 as the default instead to better fit more modern code. This would require modifying But I think a "better" fix would be to also more broadly cleanup the caching that I believe it's fine for us to state that a user manually modifying the code page, such as by calling the Win32 APIs themselves, is undefined behavior and that they should only do it via |
I assume that Win32 console did not support UTF-16 and that's why we decided to skip the call in that case. Is it no longer the case? if yes, do we know when Win32 console started supporting UTF-16? |
Description
When setting the
OutputType
toWinExe
, the console output is encoded incorrectly, resulting in garbled text.Reproduction Steps
OutputType
toWinExe
.You will notice that the encoding of
StandardOutput
in the console is set toCodePage=0
, which causes other software attempting to capture the application's output to display garbled text for some Unicode content.I have written a simple demo program to illustrate this issue. Here is my code:
You can access the entire project code from https://github.com/lindexi/lindexi_gd/tree/0dc56dbf6f635a7cc9cbda295b1cbe40c2eab8d9/Workbench/YemwearqufeballnoBayboqemli
Expected behavior
When setting
OutputType
toWinExe
, it should still be possible to obtain the correct output encoding.Actual behavior
Currently, it results in garbled text. This directly affects debugging WinExe applications in Rider, and it is not possible to set
Console.OutputEncoding
to UTF-8.Reference: dotnet-campus/dotnetCampus.Logger#32
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: