← Back to blog
Archive · WASM2019-05-04 · 1 min

WasmSample: .NET on WebAssembly with Mono.WebAssembly.Sdk

Archive note: I first shared this article on May 4, 2019 at x.com/jacano35. I republish it here in 2026. The code is at github.com/jacano/WasmSample.

In 2019 I published WasmSample, a small demonstration of .NET running in a browser as WebAssembly. No plugin required.

A C# project builds with the Mono.WebAssembly.Sdk toolchain into a WebAssembly module and a mono.js loader, and the browser page loads both over HTTP because a browser refuses WebAssembly from a local file. The five IL opcodes in the note, neg, not, switch, throw and nop, are the 2017 work in dotnet/corert, a different toolchain from this 2019 sample.

Why WASM

WebAssembly runs compiled code in the page. That let me keep the browser-side logic in C# instead of rewriting it in JavaScript.

The project also closed a circle. In 2017 I added WASM support for five IL opcodes (neg, not, switch, throw and nop) to dotnet/corert. This sample uses a different toolchain, Mono, but the idea is the same: .NET compiled for the browser.

What is inside

  • A Shell project: the HTML page and the JavaScript that loads the runtime.
  • A WASM project: the C# code, built with Mono.WebAssembly.Sdk.
  • A build.sh script and a scripts folder: the build.

Run it

The sample targets the 2019 Mono toolchain, so a current SDK may refuse to build it. Serve the output over HTTP instead of opening the file. Browsers do not load WebAssembly from file://. The README has the steps as they were at the time.