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.
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.shscript and ascriptsfolder: 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.