This is just a nod to the Mono.Cecil project which I decided to used on this project for interrogating assemblies.

This is a great open source solution which you can find more details about here: http://www.mono-project.com/Cecil

Why use Mono.Cecil?
Well .. as part of the Solution Validator build we need to be able to check assembly files which are being installed. This was particularly needed to check the Public Key Token for each assembly coming through.

I originally tried simply using the .Net Framework Assembly object and calling ReflectionOnlyLoad .. although this ended up with the assembly actually loaded into memory which was both a BAD thing to do .. but also caused locking issues if the validator tried running a second time (as the same assembly cannot be loaded twice).

To counter that I did look at using temporary .Net Framework App Domains and loading the assembly there (which can then be unloaded to free up memory). This had two major drawbacks .. firstly ReflectionOnlyLoad isn't available (just the full-on Load method) and secondly the new AppDomain didn't seem to know about Sandbox assemblies and I kept getting "cannot find file or assembly reference" errors.

I eventually got suggested to use the Mono.Cecil project from fellow twitter user massimoprota twitter.com/massimoprota and after checking it out found it was truly awesome :)
It basically uses all sorts of magic to look into the actual manifest definitions of assemblies (and even has some reflection / dissasembler stuff in the pipeline too!) without loading the assembly into memory at all!

This was exactly what I needed .. so I downloaded the project, compiled it, and you can find a reference DLL in the source code :)

Last edited Jul 3, 2011 at 11:17 AM by MartinHatch, version 2

Comments

No comments yet.