Console.WindowWidth fails with IOException
See original GitHub issuemoved from https://github.com/dotnet/corefx/issues/7858 /cc @twsouthwick
Try the following:
Program.cs:
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine($"Width: {Console.WindowWidth}");
}
}
}
project.json:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002424"
}
},
"frameworks": {
"netcoreapp1.0": {}
}
}
The fails with the following exception:
Unhandled Exception: System.IO.IOException: The handle is invalid
at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.ConsolePal.get_WindowWidth()
at System.Console.get_WindowWidth()
at ConsoleApplication.Program.Main(String[] args)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:8 (2 by maintainers)
Top Results From Across the Web
c# - System.IO.IOException when calling System.Console. ...
When making calls to any one of System.Console.BufferWidth , System.Console.CurserLeft or System.Console.WindowWidth I am greeted with a System.
Read more >Console.WindowWidth Property (System)
Attempting to set the value of the WindowWidth property when output is redirected throws either an ArgumentOutOfRangeException or an IOException exception. To ...
Read more >[Solved]-System.IO.IOException when calling System.Console ...
IO.IOException when calling System.Console.WindowWidth-C#. ... <summary> Either the type of the specified file is unknown, or the function failed.
Read more >Calling Console.WindowWidth during a Calamari script ...
As one of my deployment steps, I package up a SimpleMigrations project to migrate the database. It runs fine locally and when executed...
Read more >External console window is blank (shows no program output ...
Duplicates 1 issue (0 unresolved). RIDER-20622 external terminal throws an exception Console.WindowWidth fails with IOException.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m suddenly seeing this issue in one of my .NET 5 console apps. It’s new, so, perhaps a regression?
Still an issue