[Mono-bugs] [Bug 579252] New: Array.AsReadOnly(x).CopyTo does not copy anything

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Feb 11 14:17:26 EST 2010


http://bugzilla.novell.com/show_bug.cgi?id=579252

http://bugzilla.novell.com/show_bug.cgi?id=579252#c0


           Summary: Array.AsReadOnly(x).CopyTo does not copy anything
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.6.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: cdhowie at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7)
Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)

Array.AsReadOnly with an array (byte[] in my case) returns a read-only wrapper
around the array (of course).  But this wrapper's CopyTo method does nothing at
all.

This causes IEnumerable.ToArray to fail when applied to the result of an
Array.AsReadOnly call, because it uses ICollection<T>.CopyTo if the enumerable
is a collection.

See the following output from csharp:

csharp> ((System.Collections.Generic.IEnumerable<byte>)(new byte [] {1, 2,
3})).ToArray ();
{ 1, 2, 3 }
csharp> Array.AsReadOnly(new byte [] {1, 2, 3}).ToArray();
{ 0, 0, 0 }

Reading the code, I cannot see how this happens, because the two wrappers
around the array simply call into their wrapped objects' CopyTo method.  So it
*should* work... and yet it does not.

Reproducible: Always

-- 
Configure bugmail: http://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