Cecil documentation, the mysterious TypeDefinition <Module> and differences from reflection

622 views
Skip to first unread message

Artun

unread,
Apr 11, 2008, 1:23:40 PM4/11/08
to mono-cecil
Hello,

I am developing a framework which represents .NET assemblies as XML
documents, mainly to allow easier analyzation of .NET assemblies using
XML query languages. I am using Mono and Cecil to develop my component
which converts CIL into XML. Cecil is simple to use and quite
powerful. Thanks for this great library. :)

I have a couple of questions:

1) What is the meaning of the first module in the MainModule.Types? It
has a FullName called <Module>. It does not have a namespace or types.
(It can also be seen in the first example of the Cecil faq:
http://www.mono-project.com/Cecil:FAQ)

2) Is there a documentation for Cecil (other than source code)?

3) http://www.mono-project.com/Cecil states this following:
"Reflection and Reflection.Emit only expose a subset of all the
features in a CLI image.". Which features in particular can be
introspected with Cecil, that can not be introspected by reflection?
(Just the most important features would be sufficient)

Best regards,

Artun

Jb Evain

unread,
Apr 11, 2008, 1:31:41 PM4/11/08
to mono-...@googlegroups.com
Hey,

On 4/11/08, Artun <asu...@gmail.com> wrote:
> 1) What is the meaning of the first module in the MainModule.Types? It
> has a FullName called <Module>. It does not have a namespace or types.

It's part of the spec, to be valid an assembly has to have a <Module>
type. Some languages use that type for global methods or globals
variables.

> 2) Is there a documentation for Cecil (other than source code)?

Nop. It has plenty of examples all over the place though.

> 3) http://www.mono-project.com/Cecil states this following:
> "Reflection and Reflection.Emit only expose a subset of all the
> features in a CLI image.". Which features in particular can be
> introspected with Cecil, that can not be introspected by reflection?
> (Just the most important features would be sufficient)

* Sys.Reflection only gives you a very primitive access to the CIL
code of the methods (a simple byte []), while Cecil gives you a more
advanced view on this.

* There's a lot of little details I'll let you dig that Cecil can
handle, and that System.Reflection can not.

--
Jb Evain <j...@nurv.fr>

Artun

unread,
Apr 11, 2008, 2:13:24 PM4/11/08
to mono-cecil
Thanks for the quick reply.

Where can I find more information about the <Module> type? Search
engines like google and yahoo are omitting the '<>' characters, so I
can't really search for it. Maybe you could point me to the specs you
mentioned?

Regards,

Artun

On Apr 11, 7:31 pm, "Jb Evain" <j...@nurv.fr> wrote:
> Hey,
>
> On 4/11/08, Artun <asub...@gmail.com> wrote:
>
> > 1) What is the meaning of the first module in the MainModule.Types? It
> > has a FullName called <Module>. It does not have a namespace or types.
>
> It's part of the spec, to be valid an assembly has to have a <Module>
> type. Some languages use that type for global methods or globals
> variables.
>
> > 2) Is there a documentation for Cecil (other than source code)?
>
> Nop. It has plenty of examples all over the place though.
>
> > 3)http://www.mono-project.com/Cecilstates this following:

Jb Evain

unread,
Apr 11, 2008, 2:14:54 PM4/11/08
to mono-...@googlegroups.com
On 4/11/08, Artun <asu...@gmail.com> wrote:
> Where can I find more information about the <Module> type? Search
> engines like google and yahoo are omitting the '<>' characters, so I
> can't really search for it. Maybe you could point me to the specs you
> mentioned?

You can google for "ECMA 335".

--
Jb Evain <j...@nurv.fr>

Artun

unread,
Apr 20, 2008, 11:49:11 AM4/20/08
to mono-cecil
Hi again,

On Apr 11, 7:31 pm, "Jb Evain" <j...@nurv.fr> wrote:
> > 1) What is the meaning of the firstmodulein the MainModule.Types? It
> > has a FullName called <Module>. It does not have a namespace or types.
>
> It's part of the spec, to be valid an assembly has to have a <Module>
> type. Some languages use that type for global methods or globals
> variables.
> --
> Jb Evain <j...@nurv.fr>

I noticed today that the output doesn't contain a type called <Module>
if I disassemble my assemblies with monodis. Using Cecil, I see that
an empty <Module> type is there.

Does monodis skip the <Module> type because it is empty? Any ideas
there?

Artun

unread,
Apr 20, 2008, 11:54:46 AM4/20/08
to mono-cecil
An update to my previous question. Eventhough normal output of monodis
doesn't contain any infos about the <Module> type, running monodis
with the--typedef flag shows an empty type.

Typedef Table
1: (null) (flist=1, mlist=1, flags=0x0, extends=0x0)
2: HelloWorld.MainClass (flist=1, mlist=1, flags=0x100000,
extends=0x5)
3: TestSpace.TestClass (flist=1, mlist=3, flags=0x100000, extends=0x5)
4: SomeOtherSpace.SecondClass (flist=1, mlist=6, flags=0x100001,
extends=0x5)

I assume the first typedef 1: (null) is the <Module> type itself.
Reply all
Reply to author
Forward
0 new messages