question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console.WindowWidth fails with IOException

See original GitHub issue

moved 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:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
CerebralMischiefcommented, Feb 14, 2021

I’m suddenly seeing this issue in one of my .NET 5 console apps. It’s new, so, perhaps a regression?

0reactions
felix-ricommented, Mar 9, 2022

Still an issue

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found