[Mono-bugs] [Bug 688033] New: Arrays don't support MemberwiseClone

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Apr 17 14:04:55 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=688033

https://bugzilla.novell.com/show_bug.cgi?id=688033#c0


           Summary: Arrays don't support MemberwiseClone
    Classification: Mono
           Product: Mono: Runtime
           Version: SVN
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: misc
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: st at quanttec.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24
(KHTML, like Gecko) Chrome/11.0.696.44 Safari/534.24

Calling MemberwiseClone on arrays through reflection doesn't work in Mono,
though it works in .Net.

I stumbled over this issue while debugging a generic cloning service that uses
the MemberwiseClone method for all "blittable" objects. Of course, a workaround
would be to use the Clone method for arrays instead, but this still seems like
a Mono bug.

Reproducible: Always

Steps to Reproduce:
Compile and execute the following C# code:

using System;
using System.Reflection;

namespace Test {
    class Program {
        static object MemberWiseClone(object obj) {
            var mi = obj.GetType().GetMethod("MemberwiseClone",
BindingFlags.Instance | BindingFlags.NonPublic);
            return mi.Invoke(obj, null);
        }

        static void Main(string[] args) {
            var array = new int[]{1, 2, 3};
            var cloneObj = MemberWiseClone(array);
            var clone = (int[])cloneObj;
            System.Console.WriteLine("Clone's length: {0}", clone.Length);
        }
    }
}

Actual Results:  
MemberwiseClone silently returns a corrupt object and the program throws an
exception when it tries to cast the object to the array type.

Expected Results:  
The program does not throw an exception and prints a length of 3.

-- 
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