Blazor: a web UI framework running C# and .NET in the browser

Luke Canvin

The next generation of ASP.NET is on the horizon

Back in August we ran a lunchtime miniconf video that introduced us to Blazor. It began as a proof of concept from ASP.NET team member Steve Sanderson, who saw an opportunity to run C# and .NET code natively in the browser by compiling it to WebAssembly – a highly performant, assembly-like language that runs alongside JavaScript.

Back then he was using an old open-source project called DotNetAnywhere to provide access to a basic .NET runtime that could be compiled to WebAssembly. He was able to create a simple web app framework, which he called Blazor, that let him run a .NET web app, written in C#, serving pages to the user directly from code running on the browser’s JavaScript engine.

This was an exciting prospect, and although Blazor was a quickly hacked-together concept, it rapidly gained a lot of interest from developers, who could see the potential of being able to write client-side app code using C# and .NET, even sharing code between back and front end.

Mono to the rescue

One important missing piece was a proper .NET runtime that could run in WebAssembly. In steps Mono, which has been part of Microsoft since 2016 and a key part of Xamarin’s cross-platform support. Mono announced that it would be supporting WebAssembly, meaning that there would indeed be a full and Microsoft-backed implementation of the .NET runtime that could run in a browser.

Becoming an official ASP.NET project

Skip forward to 6 February 2018, when the ASP.NET team announces that it has brought the project into its portfolio, initially as an “experimental project” and already available open source on github, with issue tracker, ability to submit pull requests, and so on. The team’s intention is to develop it into an app framework that allows you to use .NET to build the client side of your application, an alternative to React, Angular, etc. This means:

  • a component model for building composable UI
  • routing
  • layouts
  • forms and validation
  • dependency injection
  • JavaScript interop (to call into ‘normal’ JavaScript libraries and APIs)
  • live reloading in the browser during development
  • server-side rendering
  • full .NET debugging both in browsers and in the IDE
  • rich IntelliSense and tooling
  • ability to run on older (non-WebAssembly) browsers via asm.js polyfill
  • publishing and app size trimming

The future of ASP.NET

This has the feeling of something big. There seem to be few technical impediments that could throw it off course. The team just needs to build out its framework and tooling. To me, it seems there is little chance this will not be a new direction for ASP.NET and one that is sure to be extremely popular with .NET development teams, both for the front/back-end code sharing and the ability to leverage their existing skills and tools.

Steve Sanderson has posted an article on some deeper technical details of how the framework works (there’s also an FAQ). He also mentions that while still in its very early days, it’s not too early to take a look and even to contribute. If you ever wanted to make an impact on the future of .NET, this is a real opportunity.

PS: the fact that Mono is now running on WebAssembly also provides Xamarin with the possibility to publish Xamarin.Forms apps to the web. That’s a lot more work than Blazor, but you can’t help but imagine that they have an ambition to make it happen.

  • Peter Morris

    Blazor is ace. I spent the past year developing software in Angular + NGRX/Store. So much boilerplate! So for a learning exercise I decided to write a Flux/Redux library for Blazor. Having strong-typing and reflection from C# made it a fantastic experience! Blazor is going to replace those javascript libraries, without a doubt!

    PS: Project name is “Blazor-Fluxor” on GitHub – https://mrpmorris.github.io/blazor-fluxor/