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

Eyal Alaluf eyala at mainsoft.com
Mon Jun 12 12:24:59 EDT 2006

Attaching changes to makefiles as well.

Date: Mon, 12 Jun 2006 18:38:30 +0300 (IDT)
From: Eyal Alaluf <eyala at mainsoft.com>
To: Jb Evain <mono at evain.net>
Cc: Vladislav Spivak <spivak at mainsoft.com>, mono-devel-list at lists.ximian.com
Subject: Re: [Mono-Dev] Cecil bug with Custom Attributes with enum parameters

Hi, JB.

Attached is a patch containing the assembly resolver and its usage to resolve
the actual enum type definition ad the enum underlying type.
Several notes about the patch:
   * The resolver is very simple. It searches for <assembly name>.dll in a
     given search path.
       * It doesn't handle issues that may come to mind like thread safety,
         circular dependencies between assemblies, etc.`
   * Since Cecil does not have a search path defined, I made the resolver
     optional as a public field of AssemblyFactory.
   * I also declared an interface for the resolver that will allow more
     complex and customized implementation.
   * I'd recommend adding the "GetEnumUnderlyingType" as a public service.
     Maybe it makes sense to define an IEnumTypeDfinition and add to it an
     "UnderlyingType" property?

I can propose as an alternative design:
   1. Delay load the custom attributes
   2. Provide a way to resolve all the type references in the assembly.
        * Add an "ITypeDefinition TypeDef" property to "ITypeReference".
        * After initial load of the assembly, the developer can loop over the
          assembly's type references and set this property to the resolved 
   3. The custom attribute code will use the new property whenever it has an
      unresolved type reference.
As this design is more complex and not developer friendly, I didn't follow it
through. Its advantage is that it avoids very nicely the issues of locking
and circular dependencies.
I'd welcome your comments.


On Wed, 7 Jun 2006, Jb Evain wrote:

> Date: Wed, 07 Jun 2006 19:59:12 +0200
> From: Jb Evain <mono at evain.net>
> To: Eyal Alaluf <eyala at mainsoft.com>
> Cc: Vladislav Spivak <spivak at mainsoft.com>, 
> mono-devel-list at lists.ximian.com
> Subject: Re: [Mono-Dev] Cecil bug with Custom Attributes with enum 
> parameters
> Hi Eyal,
>> 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.
> The plan is indeed to load the assembly which contains the type 
> definition. If you can contribute your resolver, I'll see how I can 
> integrate it. Then I'll add some kind of ForceLoad method if the custom 
> attribute is not readable at first try.
> Thanks,
> Jb
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cecil.patch
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060612/87decefc/attachment.pl 
-------------- next part --------------
Index: Mono.Cecil.dll.sources


--- Mono.Cecil.dll.sources	(revision 61523)

+++ Mono.Cecil.dll.sources	(working copy)

@@ -118,6 +118,7 @@

@@ -172,6 +173,7 @@

Index: Mono.Cecil.csproj


--- Mono.Cecil.csproj	(revision 61523)

+++ Mono.Cecil.csproj	(working copy)

@@ -310,6 +310,7 @@

     <Compile Include="Mono.Cecil\ITypeDefinitionCollection.cs" />

     <Compile Include="Mono.Cecil\ITypeReference.cs" />

     <Compile Include="Mono.Cecil\ITypeReferenceCollection.cs" />

+    <Compile Include="Mono.Cecil\ITypeResolver.cs" />

     <Compile Include="Mono.Cecil\ITypeSpecification.cs" />

     <Compile Include="Mono.Cecil\LinkedResource.cs" />

     <Compile Include="Mono.Cecil\ManifestResourceAttributes.cs" />

@@ -364,6 +365,7 @@

     <Compile Include="Mono.Cecil\TypeDefinitionCollection.cs" />

     <Compile Include="Mono.Cecil\TypeReference.cs" />

     <Compile Include="Mono.Cecil\TypeReferenceCollection.cs" />

+    <Compile Include="Mono.Cecil\TypeResolver.cs" />

     <Compile Include="Mono.Cecil\TypeSpecification.cs" />

     <Compile Include="Mono.Cecil\VariantType.cs" />

     <Compile Include="Mono.Xml\MiniParser.cs" />

@@ -386,4 +388,4 @@


     <Reference Include="System" />



\ No newline at end of file


More information about the Mono-devel-list mailing list