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: [email protected]
        ReportedBy: [email protected]
         QAContact: [email protected]
          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.
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to