Try Mono.Cecil if you need System.Reflection.Emit in Windows Phone 7 3

As .NET compact framework never support System.Reflection.Emit, we can’t use Reflection.Emit in Windows Phone 7 development. So, it prevents us from porting the existing frameworks like Unity, Castle Dynamic Proxy, Moq and etc to Windows Phone 7 development platform. I was looking all options that helps us to use Reflection.Emit in Phone 7. The first option that I check is to port Mono code to Silverlight for Phone 7 version. The second option is to use Mono Cecil that is using in Mono Core. And the third option is to use EmitCF but I don’t see any update after beta release so I guess this project is dead already. So, I decided to give a try on Mono Cecil.

Mono Cecil supports Silverlight, Compact Framework and .NET desktop version. So, it’s very easy to make Cecil work on Phone 7. All I have to do is to create a conditional called CF in csproj file and then it will work like a charm. I submitted a patch to Mono Cecil but Jb Evain said that he doesn’t want to provide csproj officially so I will make the files downloadable here.

Download ~ cecil.zip (Please use Mono.Cecil – 2010.sln and Mono.Cecil-Phone.csproj )

What is Mono Cecil?

Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. It has full support for generics, and support some debugging symbol format.

In simple English, with Cecil, you can load existing managed assemblies, browse all the contained types, modify them on the fly and save back to the disk the modified assembly.

Today it is used by the Mono Debugger, the bug-finding and compliance checking tool Gendarme, MoMA, as well as DB4O.

3 thoughts on “Try Mono.Cecil if you need System.Reflection.Emit in Windows Phone 7

  1. Reply nantcom May 15,2010 9:20 am

    Hello, I have tried to use your CeCil port – but AssemblyPart class does not expose Load function and Assembly.LoadForm is Security critical. If you can get this running – could you please advise on how you could get it running – Thanks! :)

  2. Pingback: CoreSharp.NET - อย่าพยายาม WP7 ไม่รองรับ Reflection.Emit - frontpage

  3. Reply Vivek Aug 28,2012 3:33 am

    Nice blog…
    As per my understanding you want to say that we can use Mono Cecil in windows phone 7 development to replace Reflection.

    if your ans is yes then please share any example project.(Project type require windows phone 7 )

Leave a Reply