Yes.  The error occurs in
sscli\clr\src\bcl\system\io\__consolestream.cs:

        public override void Close()
        {
            // We're probably better off not closing the OS handle here.
First,
            // we allow a program to get multiple instances of
__ConsoleStreams
            // around the same OS handle, so closing one handle would
invalidate
            // them all.  Additionally, we want a second AppDomain to be
able to 
            // write to stdout if a second AppDomain quits.
            if (_handle != Win32Native.INVALID_HANDLE_VALUE) {
                Flush();
                _handle = Win32Native.INVALID_HANDLE_VALUE;
            }
            _canRead = false;
            _canWrite = false;
        }

        public override void Flush()
        {
            if (_handle == Win32Native.INVALID_HANDLE_VALUE)
__Error.FileNotOpen();
            if (!CanWrite) __Error.WriteNotSupported();
        }

The last line throws the NotSupported exception since the stream is
read-only.

You could argue that this is a fairly minor annoyance with
OpenStandardInput() because the Close() (or Flush()) is really a no-op
since the underlying system handle is going to remain open and since the
stream is read-only so there's no data to flush.

This bug was already in the bug database.

-----Original Message-----
From: Jeroen Frijters [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, July 03, 2002 5:11 AM
To: [EMAIL PROTECTED]
Subject: ConsoleStream Bug


The following throws a NotSupportedException:

class test
{
  public static void Main(string[] args)
  {
    System.Console.OpenStandardInput().Close();
  }
}

Reply via email to