[Mono-bugs] [Bug 348751] New: System.IO.Ports.SerialPort.ReadExisting() throw NullReferenceException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Dec 14 09:56:10 EST 2007


           Summary: System.IO.Ports.SerialPort.ReadExisting() throw
           Product: Mono: Class Libraries
           Version: 1.2.5
          Platform: x86
        OS/Version: Windows XP
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at ximian.com
        ReportedBy: tom at opgenorth.net
         QAContact: mono-bugs at ximian.com
          Found By: ---

Description of Problem:
Calls to System.IO.PortsSerialPort.ReadExisting() seem to be consitently
throwing a NullReference exception when run under Mono 1.2.5+ and Win32.  I
first found this in Mono 1.2.5 a couple of weeks ago, and decided to wait and
see if the issue would be fixed in Mono 1.2.6

Steps to reproduce the problem:
1. Execute the following code snippet:


Actual Results:
NullReferenceException gets thrown.  It seems that after about three such
calls, the runtime abends with only the following message.  Note that this is
running mono --debug


This application has requested the Runtime to terminate in an unusual way.
Please contact the application's support team for more information.

Expected Results:
Should return a string, what was in the buffer (or possibly timeout).

How often does this happen? 
Every time (on Windows).

Additional Information:
* Here is a snippet from my log file (log4net generated):
2007-12-14 07:34:11,843 [   1] DEBUG
Opgenorth.Reloading.Chrony.Communications.SerialChronyPort [(null)]
System.NullReferenceException: Object reference not set to an instance of an
  at (wrapper managed-to-native) System.IO.Ports.WinSerialStream:ClearCommError
  at System.IO.Ports.WinSerialStream.get_BytesToRead () [0x00000] in
  at System.IO.Ports.SerialPort.get_BytesToRead () [0x00006] in
  at System.IO.Ports.SerialPort.ReadExisting () [0x00006] in
  at (wrapper remoting-invoke-with-check)
System.IO.Ports.SerialPort:ReadExisting ()
  at Opgenorth.Reloading.Chrony.Communications.SerialChronyPort.Open ()
[0x0007d] in

Code Snippet:
 * Note that _serialPort is a System.IO.Ports.SerialPort instance.
            if (!_serialPort.IsOpen)
                string openResult;
                    openResult = _serialPort.ReadExisting();
                catch (NullReferenceException nre)
                    openResult = string.Empty;
                    _log.DebugFormat("Assuming there is no Chrony on {0}.",
                catch (Exception)
                    throw new ConnectionFailedException(_serialPort.PortName);

                if (!ReadyResponse.Equals(openResult,
                    throw new ConnectionFailedException(_serialPort.PortName);

Here are the constants that _serialPort was configured with:
        public const int BaudRate = 4800;
        public const int DataBits = 8;
        public const Parity ChronyParity = Parity.None;
        public const StopBits ChronyStopBits = StopBits.One;
        public const Handshake ChronyHandshake = Handshake.XOnXOff;
        public const int ReadBufferSize = 2048;
        public const int WriteBufferSize = 512;
        public const int ReadTimeout = 2000;
        public const int WriteTimeout = 2000;
        public const bool RtsEnabled = true;
        public const int CommandPause = 25;

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list