Blazor .NET In The Browser
Written by Mike James   
Monday, 12 February 2018

Microsoft has yet another way to create web apps, as if we or it needed one. Blazor could be called .NET in the browser and this might make you think of Silverlight, but things aren't quite as simple.

With Silverlight Microsoft had it all - it was essentially Windows in the browser. The problem was that in-fighting and lack of a clear vision of anything much, coupled with the growing feeling that browser plug-ins were a bad, bad thing, killed Silverlight. A similar attitude seems to have affected the whole of the .NET system with only the languages being kept on, but only if you couldn't rise to the challenge of C++. Today we still have .NET desktop applications, but we also have the fairly useless Universal Windows Platform and the much misunderstood Xamarin framework. We also have so many flavors of ASP .NET that it is difficult to know what exactly is a modern current ASP .NET technology.

Now we can add to the list Blazor.

This has a certain technical interest, even if you aren't interested in .NET, because it gives us some ideas for what could be just down the road because of WebAssembly.

What is WebAssembly?

Historically we started from primitive machine languages and slowly worked our way up to something more sophisticated. In the web universe, however, time runs backward. We started with a very sophisticated language - JavaScript - and worked our way back though increasingly primitive forms - asm.js and now WebAssembly (WASM). Essentially WASM is a low level way of coding a program so that a JavaScript engine doesn't need much modification to run it - and run it as fast as possible. It is never going to be as fast as a native code program, but it can be fast enough for many tasks.

The good news is that at the moment most of the modern browsers support WASM. The bad news is that the tools to create WASM are in their early days. If you want to create a WASM program then you are probably going to have to code in C/C++ and use a command line compiler. Blazor is roughly speaking a way to write in C# or any .NET language and run in the result in the browser using WASM.. 

The idea is a bit like Silverlight in that it lets you use C#, but that's about where the similarity ends. It is not a plugin and nothing it makes use of isn't a web standard. From a programmer's point of view the biggest difference is that it doesn't use XAML, or any part of the .NET UI. As this is one of the big attractions of working in .NET, this makes Blazor less interesting.

The whole project depends on the Mono team's porting of the Mono runtime to WebAssembly. This allows .NET code to run in two possible modes. You can take the Mono runtime as a WebAssembly binary and give it your program compiled to IL (Intermediate Language) and let the runtime interpret it.

blaxor1

Alternatively you can compile the .NET code to WASM and run everything as a WebAssembly binary.

blaxor2

This copies the way that things work on the desktop with your code being interpreted at run time by the .NET runtime or being run as native code if you run it though the ngen/CoreRT tool.

If the browser isn't able to run WASM then the compiler falls back to asm.js, which isn't going to be as fast.

You might think that the full compile is the best way to go because of speed considerations, but according to Microsoft this isn't quite so obvious because interpreted code runs fast enough and IL code is more compact than WASM.

So much for the code that does the work - what about the UI?

There are a new set of UI components, which are based on the ASP .NET Razor syntax, for combining markup and C#. It is essentially .NET's reinvention of the way PHP does the job - a terrible idea. This is not a good way to ensure separation of concerns.

Is Blazor a game changer?

Most likely not. If you program in C# or any .NET language then you might be attracted by it, but as it doesn't share UI components with traditional XAML based .NET, Xamarin  or UWP apps then you are going to have to do everything differently. You will be able to use the .NET Standard 2.0 framework, but due to the constraints of running in a sandbox not all functions are going to work.  You will be able to access the DOM and interoperate with JavaScript so no real advantages here either.

At the moment it is difficult to see why anyone would choose to use Blazor. If you have an ASP.NET site and want to extend it with a single page app then there is some synergy, but apart from this the only advantage is being able to write in C#, F# or VB and run on a browser. If you are already in a hole that Microsoft has dug for you, then you might well find Blazor a useful tool.

This is not Windows in a browser. Microsoft had that in Silverlight and threw it away.

Of course it is early days. Blazor is not even alpha and although there is a GitHub page, Blazor is open source with an Apache 2 licence, using it is only for the adventurous.  I can imagine many things that could be added or modified to make Blazor very attractive - getting rid of Razor and using XAML for example  - and this means that my conclusions are also not even alpha.

More Information

A new experiment: Browser-based web apps with .NET and Blazor

https://github.com/aspnet/Blazor

Related Articles

Blazor, .NET In The Browser, Reaches 0.3

WebAssembly Is Ready For Use

WebAssembly Has Mozilla, Microsoft,Apple and Google Backing It 

WebAssembly Explorer - A Learning Tool

Silverlight Bridge To UWP Apps       

Microsoft Needs To Make Silverlight's Future Clear       

Not Dumping .NET - Microsoft's Method       

Microsoft Open Sources .NET?       

Silverlight Support Roadmap       

Silverlight is dead, long live Silverlight?

Silverlight 5 - the end of the line

Was .NET all a mistake?

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Swimm Releases Copilot Extension For Documentation
03/12/2024

Swimm, best known for its AI-driven software documentation tools, has announced an extension for GitHub Copilot. The Swimm team says the extension means developers using GitHub Copilot Chat can turn C [ ... ]



Visual Studio 17.12 Released Along With Aspire
25/11/2024

Visual Studio 2022 v17.12 is now available. The release can be used for .NET 9 projects and has a range of other improvements.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

Last Updated ( Tuesday, 26 June 2018 )