Facilitating the spread of knowledge and innovation in professional software development



Choose your language

InfoQ Homepage News Introducing dot42, a C# Compiler for Android’s Dalvik Runtime

Introducing dot42, a C# Compiler for Android’s Dalvik Runtime


The biggest downside of Mono for Android is that you are building on Mono, a completely separate runtime that what Android expects. And while there are certainly some advantages to having access to a full CLR, marshalling calls between it and Android’s Dalvik runtime can be expensive. So why not skip the IL code and emit Dex code directly?

Actually that is a slight exaggeration. The dot42 compiler doesn’t actually skip the IL. Rather, it reads the IL code and converts it into a new language called RL or Register Language. The main difference between IL and RL is that IL is stack-based (somewhat like Java’s byte code) while RL is register based. Once converted into RL, a set of optimizations are performed and the final product is compiled again. This last compilation gives us dex code, the language of Android’s Dalvik Runtime.

Through each step of the process the original .NET debugging information is maintained, though of course it must be converted from the Windows/.NET PDB format to dex’s debug information format. dot42 uses the Android Debug Bridge to connect the Visual Studio debugging facilities

Android Libraries are accessed by directly referencing JAR files. “After compilation, your calls are redirected to calls into the original Android libraries.” Some mapping between types is needed, but that is largely addressed by the compiler. For example, java.lang.Boolean is mapped to C#’s Nullable<bool>.

Because dot42 emits dex code, there are some C# features that you will not be able to use. The most notable of these is user defined value types, a.k.a. structs. Since they don’t exist in Dalvik, there is simply no way to map them.

When using dot42, you’ll often need to decide between the C# and Android versions of common data structures. For example, should you use .NET’s List<T> or Java’s ArrayList<T>? According to Ewout Prangsma, developers should favor the Java version if they are concerned about memory and download size. Even though their implementation of List<T> is basically a thin wrapper around ArrayList<T>, it is still extra code that needs to be packaged and shipped to the phone.

dot42 is a commercial product that starts at 499 Euro per developer with the usual bulk licensing options.

We need your feedback

How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Take the Survey

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.