Facilitating the spread of knowledge and innovation in professional software development



Choose your language

InfoQ Homepage News Using Mono to Compile C# to WebAssembly

Using Mono to Compile C# to WebAssembly


Since all major web browsers now include support for WebAssembly, developers can now look to having a new platform for which they can target their applications. The standard toolchain provided by the WebAssembly group will compile C/C++ to WebAssembly which doesn't help developers using other languages. Fortunately for C# programmers, the Mono Project is working on two different approaches to support WebAssembly.

The first approach utilizes the Mono IL interpreter to run managed code (like C#) at runtime. The goal of this approach is to support rapid prototyping and development. This second method would be best used when an application is ready to be shipped to a customer. This approach uses static compilation to produce a WASM file that for native execution by a browser that supports WebAssembly.

To create these WASM files, the Mono project has introduced a new tool, mono-wasm. It takes C# assemblies as input and generates LLVM bitcode for use with the LLVM WebAssembly backend. The resulting WASM file produced by mono-wasm includes all of the dependencies needed for the C# program's execution, including the mscorlib.dll, C library, and the Mono runtime. Since the LLVM linker recently added support for WebAssembly, mono-wasm supports incremental compilation. This greatly reduces compilation times as code that doesn't change (mscorlib.dll, Mono runtime, etc.) does not need to be recompiled while developing your application.

A lot of work has been accomplished by the project, but primary developer Laurent Sansonetti does point out that it is still pre-alpha. In the new near term, outstanding goals include fixing garbage collection and preparing a formal alpha release. Longer term the project will look at shrinking the size of WASM executables (the "hello world" example is 10 megabytes), updating the Mono compiler so that it can target WASM32 directly, and improving C#/JavaScript interoperation.

While this project is very much under active development, curious developers or those seeking to contribute can find the project's current code on GitHub.

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.