[Mono-bugs] [Bug 480529] New: InvalidCastException when assigning array type attribute to object type field.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Feb 27 13:25:14 EST 2009


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


           Summary: InvalidCastException when assigning array type
                    attribute to object type field.
    Classification: Mono
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Cecil
        AssignedTo: jbevain at novell.com
        ReportedBy: msafar at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


C# code looks like

class A: Attribute {
    public object D;
}

[A (D = new object[] { 1 })]
class C {}

Cecil crashes with

InvalidCastException {"Unable to cast object of type 'Mono.Cecil.TypeReference'
to type 'Mono.Cecil.ArrayType'. }


Relevant Cecil code


        static CustomAttrib.FixedArg CreateFixedArg (TypeReference type, object
value)
        {
            CustomAttrib.FixedArg fa = new CustomAttrib.FixedArg ();
            if (value is object []) {
                fa.SzArray = true;
                object [] values = value as object [];
                TypeReference obj = ((ArrayType)
type).ElementType;<---------------------
                fa.NumElem = (uint) values.Length;
                fa.Elems = new CustomAttrib.Elem [values.Length];
                for (int i = 0; i < values.Length; i++)
                    fa.Elems [i] = CreateElem (obj, values [i]);
            } else {
                fa.Elems = new CustomAttrib.Elem [1];
                fa.Elems [0] = CreateElem (type, value);
            }

            return fa;
        }

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


More information about the mono-bugs mailing list