Biz & IT —

Open source Mono framework brings C# to iPhone and Wii

Mono, an open source implementation of the .NET runtime, is being used to …

Mono, an open source implementation of .NET runtime, is bringing Microsoft's development technologies to some unexpected places, including the iPhone, Android, and the Wii.

According to Novell's lead Mono developer, Miguel de Icaza, several applications in Apple's App Store are powered by Mono. This might come as a bit of a surprise to those familiar with Apple's highly restrictive application inclusion policies, because the company strictly prohibits developers from using interpreted languages and third-party runtime environments—a constraint that largely rules out technologies like .NET and Java.

Static compilation is the special sauce that makes it possible for Mono to run on the iPhone. Mono allows developers to use ahead-of-time (AOT) compilation, which converts .NET's common intermediate language (CIL) directly to native code at compile time. This means that the application doesn't have to use just-in-time (JIT) compilation to generate the native code at runtime.

There are also a few other tricks and Mono features that developers can use to reduce the size of Mono executables and assemblies for deployment in mobile environments. You can use the Mono linker to shrink the library size, you can omit the JIT and code generation engines from the executables, and you can strip out CIL instructions from the assemblies.

Static compilation makes it possible to build Apple-approved iPhone applications with Mono, but it comes with some limitations. Generics and dynamically-generated code are currently not supported when AOT compilation is used.

There are a lot of hoops to jump through right now to set up iPhone cross-compilation for Mono, but de Icaza says that developers who want to start now can use Unity, a third-party commercial programming framework for 3D game development that is built on Mono. Unity supports several platforms, including the iPhone and the Wii, and comes with its own built-in Mono cross-compilation environment.

In a blog post published this week, de Icaza identifies almost 40 applications (most of which are games) in Apple's App Store that are built on Unity and Mono. He also wrote about My Animal Center, a German game for the Wii that is heavily coded in C# using Unity and Mono.

The iPhone isn't the only hot handset to catch Mono. A developer has experimentally ported the Mono runtime to the Android-based T-Mobile G1. Although this port is only an experimental proof of concept and won't be used to deploy applications on the platform any time soon, it has a lot of potential and performs well against Google's Dalvik runtime in some preliminary benchmarks.

Mono's robust portability and advanced support for features like static compilation are enabling developers to use it in innovative ways that wouldn't be possible with Microsoft's .NET implementation. This demonstrates the value and flexibility inherent in an open implementation.

Channel Ars Technica