Console.ReadKey not possible in debug

Hi

I have a .NET Core console app running on Torizon. But when debugging ReadKey does not work. It simply crash.
I can use Read, but I also need to get the modifiers like Ctrl or Alt.

Why is this not possible when debugging?
I type in the VSC terminal or must I use a diffrent terminal. SSH into instead?

Thomas

Greetings @TJO,

Could you provide a small sample code that displays this behavior. So that we may try and reproduce/experiment with the issue on our side.

Furthermore what version of our VSCode extension are you running? And does your project have any configurations that we’d need to know about in order to reproduce this?

Best Regards,
Jeremias

Hi

I have version 1.3.0 of torizon extension. I just created the .NET COre console app with no specific configurarion.

Try this code. When debug I get an exeption but not in release?

using System;

namespace ConsoleInput
{
    class Program
    {
        static void Main(string[] args)
        {
            var KeyInfo = Console.ReadKey(true);
            Console.WriteLine(KeyInfo.Key);
        }
    }
}

Thank you for the sample code. I see the issue now. When I try to run the debugger on this code, the error I get is as follows:

Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.

This is probably occurring due to how the console output is being handled due to being in a container and also during the debugging. When running in release a console can be properly allocated to the container, but for debugging this complicates things.

Let me check in with our IDE team and see if they have any ideas here.

Best Regards,
Jeremias

Hi

Yes and the Console.Read. does work in Debug it seems. So ReadKey and Read must work dirrently

Thomas

I checked with our IDE team and this is actually a known limitation at the moment. For the debugging to work correctly with containers we have to run them detached from stdin. This explains why the issue is only with debug and not release.

I’m not too familiar with .NET so I can’t say why Read is okay but not ReadKey. Anyways, the team said it might be possible to remove this limitation, but at the moment I don’t have any timelines on when they might have a solution here.

In the meanwhile, if possible you might have to temporarily use Read just for debugging purposes.

Best Regards,
Jeremias