[Mono-bugs] [Bug 74953][Maj] New - List<byte>.AddRange throws NullReferenceException

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sun May 15 00:47:48 EDT 2005


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 emrysk at gmail.com.

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

--- shadow/74953	2005-05-15 00:47:48.000000000 -0400
+++ shadow/74953.tmp.27079	2005-05-15 00:47:48.000000000 -0400
@@ -0,0 +1,53 @@
+Bug#: 74953
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: Ubuntu Linux 5.05 (Hoary)
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Major
+Component: CORLIB
+AssignedTo: martin at ximian.com                            
+ReportedBy: emrysk at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: List<byte>.AddRange throws NullReferenceException
+
+I'm using Mono 1.1.7 built from source on Ubuntu (Hoary).
+
+The following is a working example.  It throws a NullReferenceException
+from AddRange.
+
+using System.Collections.Generic;
+class Program {
+	static void Main() {
+		List<byte> list = new List<byte>();
+		byte[] bytes = new byte[] { 100, 100 };
+		list.AddRange(bytes);
+	}
+}
+
+This is the odd bit, though.  If I call:   foreach (byte b in bytes)
+list.Add(b);   instead of AddRange, it works just fine.  Looking at Mono's
+source, AddRange is implemented in this chunk of code, which should be
+identical to what I'm doing with foreach:
+
+[MonoTODO ("PERFORMANCE: fix if it is an IList <T>")]
+public void AddRange(IEnumerable<T> collection)
+{
+       foreach (T t in collection)
+               Add (t);
+}
+
+Perhaps this is a bug with IEnumerable<byte>?
+
+Here's the exception dump:
+
+Unhandled Exception: System.NullReferenceException: A null value was found
+where an object instance was required.
+in <0x00022> System.Collections.Generic.List`1<System.Byte>:AddRange
+(IEnumerable`1 )
+in <0x0006d> Program:Main ()


More information about the mono-bugs mailing list