Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report for Bug 10106 on
GitHub or Developer Community if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
Created attachment 3339 [details]
This is a Windows-specific issue.
If the caller/parent process mono calls SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE), then mono will bomb during process startup.
1. Download invalid-handle.zip
2. Extract it.
3. From CMD.EXE:
> cd path\to\invalid-handle
> NMAKE all
> NMAKE run
Expected results: To do what .NET does:
> .\EXEC.EXE HW.EXE
> # Clearing stdin...
> [stdout] Hello, world!
> # exit code: 0
Actual results: standard error contains:
> [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Console ---> System.ArgumentException: handle
> Parameter name: Invalid.
> at System.IO.FileStream..ctor (IntPtr handle, FileAccess access, Boolean ownsHandle, Int32 bufferSize, Boolean isAsync, Boolean isZeroSize)
> at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (intptr,System.IO.FileAccess,bool,int,bool,bool)
> at System.Console.Open (IntPtr handle, FileAccess access, Int32 bufferSize)
> at System.Console.OpenStandardInput (Int32 bufferSize)
> at System.Console.SetupStreams (System.Text.Encoding inputEncoding, System.Text.Encoding outputEncoding)
> at System.Console..cctor ()
> --- End of inner exception stack trace ---
> at Test.Main ()
Export MONO_LOG_LEVEL=debug, and the last useful message written to stdout is:
> Mono: Searching for 'GetConsoleOutputCP'.
Based on those two items, what appears to be happening is that Console.OpenStandardInput(int) calls Console.Open(MonoIO.ConsoleInput, FileAccess.Read, bufferSize).
MonoIO.ConsoleInput is an internal call into mono/metadata/file-io.c!ves_icall_System_IO_MonoIO_get_ConsoleInput():
The problem is that because the caller has deliberately/explicitly set STD_INPUT_HANDLE to INVALID_HANDLE_VALUE, MonoIO.ConsoleInput returns INVALID_HANDLE_VALUE, which causes the FileStream constructor to throw.
What should happen? Perhaps ves_icall_System_IO_MonoIO_get_ConsoleInput() should return NULL if GetStdHandle() returns INVALID_FILE_HANDLE?