[Mono-Dev] Cecil bug with Custom Attributes with enum parameters

Eyal Alaluf eyala at mainsoft.com
Wed Jun 7 12:04:22 EDT 2006

Hi, JB.

I stumbled upon a critical problem with custom attributes that have enums in their
ctor.  For instance:
The problem is as follows -
     * Custom attribute signatures aren't self contained. They depend on
       interpreting the parameters of the custom attribute ctor referenced in the
     * If a parameter is an int32 then 4 bytes in little endian are read, etc.
     * If the parameter is an enum - one has to find out the enum underlying type
       and read the value from the Blob according to its underlying type (e.g. int).
     * Now when the enum comes from another assembly, Cecil only has a TypeReference
       to it and actually has no idea that it's an enum and definitely not what
       is the underlying type.
     * The code at Mono.Cecil.Signatures/SignatureReader.cs:746 method
       CustomAttrib.Elem ReadElem (byte [] data, BinaryReader br,
                                   TypeReferenceelemType, ref bool read) says:
         default : // enum
             read = false;
             return elem;
       which means that the custom attribute is not fully processed.
     * The result is that we get a CustomAttribute without the values for the ctor
       parameters and without the values for the named parameters.

I understand that the main difficulty is that the only way to find the enum's
underlying type is to actually load the enum's assembly (which could be another
assembly then the currently processed assembly).
We are currently doing this for all TypeReferences we encounter. We are using Cecil
itself to load the referenced assembly and look for the referenced type. Currently
Cecil tries to process each assembly independently of other assemblies and this
goes strongly against this design.

Do you have any plans to resolve this issue? (I assume from the comment in the code
that you are familiar with it)
What is the design you are looking for in this case? If you want to have Cecil
loading the Enum we can contribute our Resolver that is Cecil based.

Thanks, Eyal.

More information about the Mono-devel-list mailing list