Dumpify
Dumpify copied to clipboard
Character encoding problem in PowerShell (rare & intermittent)
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.
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");
}
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
.
@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?
Closing since I couldn't reproduce it
The Solution:
System.Console.OutputEncoding = System.Text.Encoding.UTF8;