How to run .Net apps in the browser with Blazor

Microsoft’s Blazor experiment uses modern web technologies like WebAssembly to put a .Net runtime inside your browser

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

We all remember Silverlight, Microsoft’s answer to Adobe’s Flash. The remnant of an ambitious plan to have .Net code running everywhere, it mixed the familiar C# and XAML with browsers. The result was a richer, more interactive web experience than familiar forms with a dash of CSS. As useful as plugins were, it became clear that they made the browser attack surface much bigger. Flash and ActiveX exploits became a serious security risk, and designers and developers began to back away from the world of plugins.

A new generation of more powerful browsers helped the transition, along with the opening of a corresponding new front in the never-ending browser wars: browser performance benchmarks. New JavaScript engines like Internet Explorer’s (and now Edge’s) Chakra came along with JIT compilers that took advantage of new processor capabilities and soon rivaled binary code. Along with better performance, the web itself added more capabilities, with HTML5’s new JavaScript and CSS constructs quickly providing alternatives to now-obsolete plugin technologies, from 2D animations to virtual reality.

Instead of plugins, we now use extensions. They’re safer, but they don’t have the speed or the capabilities of a plugin like Silverlight. Because they rely on JavaScript, HTML, and CSS, they provide seamless integration with the browser. But they don’t let us take advantage of advanced language features in C# or Go, or of newer hardware graphics capabilities.

WebAssembly is the power behind Blazor

Google’s experiments with NaCl, its Chrome native client, alongside Mozilla’s work with ASM.js, led to the development of the World Wide Web Consortium’s WebAssembly, aka Wasm. At the heart of WebAssembly is a simple virtual machine that can work with precompiled code that’s delivered in a compact binary encoding. Although WebAssembly code isn’t human-readable, the specification includes a way of representing it that looks very much like classic assembly language.

Any compiler can deliver WebAssembly code, from any language, and it can run nearly as fast as compiled binary code. There’s an added advantage too, because it only runs verified code in a browser-hosted sandbox. With the additional security features of a modern browser like Edge, the result is highly secure code that only has very limited access to system resources. That makes WebAssembly an attractive alternative to JavaScript, hosting fast and responsive web-based user interfaces.

To continue reading this article register now