Closed alexrp closed 4 years ago
Perhaps relevant: This is running under WSL 2. Starting a fresh shell or terminal appears to fix it.
File is locked. Be sure to dispose your object upon app termination and that no zombie pids are lingering. Rebuild, rereun. Only the std streams and the original target invocation utilizing the readline library are applicable. I would check to be sure your app isn't throwing an internal exception and that it terminates properly.
Possible race/thread scheduling issue during disposition?
Wait, why would it matter how the app terminates? It's just the stdin stream; it's not a thing that persists across multiple runs of the app.
Console.In uses the STDIN stream.
The ReadLine method executes synchronously. That is, it blocks until a line is read or the Ctrl+Z keyboard combination is pressed. The In property returns a TextReader object that represents the standard input stream and that has both a synchronous TextReader.ReadLine method and an asynchronous TextReader.ReadLineAsync method. However, when used as the console's standard input stream, the TextReader.ReadLineAsync executes synchronously rather than asynchronously and returns a Task
Are you calling this using dependancy injection or across application domains?
Neither. I am simply invoking ReadLine.Read()
directly from the main thread.
I'm not sure sure this point without debugging your code.
Check the calling scope using blocks lifetime, in conjunction with any subsequent calls associated for readline.
It appears that you have some threading/async invocations going on which would need to be scheduled or dispatched accordingly.
You claim its on the main thread, but according to the ST, the stream is already open and locked while it tries to open it again.
Can you ensure the stream is closed before attempting to use it again?
I do not have any other code that's accessing Console.In
in any way, hence my confusion.
I am certain it's executing on the main thread - despite the InvokeAsync
in the stack trace, my command handler delegate is not async
, nor does it return a Task
, so System.CommandLine executes it on the main thread.
This issue seems to have gone away completely at some point, so I'll go ahead and close this.
When using ReadLine in my .NET Core app (running through
dotnet run
), I sometimes get this:It's not consistent, and I'm not sure how to reliably reproduce it. I am also using System.CommandLine in this app, so at first I thought there might be some kind of conflict, but I don't believe that is the case as System.CommandLine does not appear to touch
Console.In
anywhere.