Dumpify icon indicating copy to clipboard operation
Dumpify copied to clipboard

Character encoding problem in PowerShell (rare & intermittent)

Open dgilleland opened this issue 11 months ago • 2 comments

I'm "re-using" Dumpify as a way to do a quick'n'dirty representation of a 2D array of char values for a BattleShip concept. It's just a temporary usage for a concept presentation. But I've noticed a very rare and unpredictable messing up of the border characters every once in a while when I run my code (even without code changes). Here's what I'm seeing.

image

When it happens, it's not always those incorrect characters - sometimes it's different ones. Again, this is quite rare and hard to reproduce. The code usage is quite simple (.NET 8 console app, running in PowerShell, on Windows 11):

void Concept()
{
    char[,] grid = new char[10,10];
    // Initialize
    for(int row = 0; row < 10; row++)
        for(int col = 0; col < 10; col++)
            grid[row,col] = Random.Shared.Next(10) switch
            {
                < 7 => ' ',
                >= 7 and < 9 => '-',
                _   => Random.Shared.Next(5) switch
                {
                    < 4 => '-',
                    _ => 'H'
                }
            };

    grid.Dump("Player Won");
}

dgilleland avatar Feb 28 '24 12:02 dgilleland

Hi, thanks for reporting this! I will try to reproduce it to look further into it, although it is more likely to be a bug in Spectre.Console.

MoaidHathot avatar Feb 28 '24 23:02 MoaidHathot

@dgilleland, I tried running the code in a loop for 5-10 minutes but it didn't reproduce for me. Does it still reproduce for you?

MoaidHathot avatar Mar 18 '24 06:03 MoaidHathot

Closing since I couldn't reproduce it

MoaidHathot avatar Aug 24 '24 07:08 MoaidHathot

The Solution: System.Console.OutputEncoding = System.Text.Encoding.UTF8;

code1line avatar Sep 17 '24 11:09 code1line