[Mono-bugs] [Bug 82574][Wis] New - Implementation of SerialPort.ReadByte may be inconsistent with MSDN documentation

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Aug 24 12:18:19 EDT 2007


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by phbaer at npw.net.

http://bugzilla.ximian.com/show_bug.cgi?id=82574

--- shadow/82574	2007-08-24 12:18:19.000000000 -0400
+++ shadow/82574.tmp.19651	2007-08-24 12:18:19.000000000 -0400
@@ -0,0 +1,76 @@
+Bug#: 82574
+Product: Mono: Class Libraries
+Version: 1.2
+OS: 
+OS Details: Ubuntu Feisty AMD64
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: phbaer at npw.net               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Implementation of SerialPort.ReadByte may be inconsistent with MSDN documentation
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+Implementation of SerialPort.ReadByte is inconsistent with MSDN
+documentation: ReadByte returns -1 if an error occurs:
+
+internal int read_byte ()
+{
+	byte [] buff = new byte [1];
+	if (stream.Read (buff, 0, 1) > 0)
+		return buff [0];
+
+	return -1;
+}
+		
+public int ReadByte ()
+{
+	CheckOpen ();
+	return read_byte ();
+}
+
+AFAIK it should return a InvalidOperationException:
+
+MSDN:
+"InvalidOperationException The specified port is not open."
+
+
+Steps to reproduce the problem:
+1. Open serial port
+2. Generate some error (unplug usb-serial cable, ...)
+3.  
+
+Actual Results:
+If reading a byte from the stream returns -1, the ReadByte method also
+returns -1.
+
+Expected Results:
+An exception should be thrown
+
+How often does this happen? 
+Always
+
+Additional Information:
+When reading a line from the serial port (ReadLine) and an error occurs
+(cable of an usb-to-serial converter is unplugged, for instance), the
+ReadLine method is stuck in its read loop:
+
+public string ReadLine ()
+[...]
+while (true){
+	int n = stream.Read (buff, 0, 1);
+	if (n == -1 || buff [0] == '\n')
+		break;
+	bytes_read.Add (buff [0]);
+} 
+
+This is because stream.Read() may also return 0 (in case of an error). This
+is a similar bug so I didn't report another one.


More information about the mono-bugs mailing list