Haven’t heard of WebAssemblies yet? Check some other articles to shortly educate yourself about WebAssemblies before continue reading.
Ok, but what about C#? As far as my research did take place, there is currently Mono and Microsoft working on a project (Experimental). Since the Mono Project on GitHub lacks too much guidance and I haven’t the power of will to read through their code, we will just skip their experimental project in this article. (Side note: Blazor runs on Mono)
Lets get into it! The repro of the Blazor project can be found on GitHub.
File -> New -> Project -> ASP.NET Core Web Application
Select Blazor as a project template. If there is no Blazor template, you are missing the Blazor Language Extension, mentioned above. The Blazor template does not require a server running an IIS. The hosted one (ASP.NET Core hosted) does, but provides the advantage of a .NET server backend as well.
And we are ready to go. Select the browser of your choice and start the application.
What just happend?
We are running a .NET Application directly in the browser! Lets have a quick peek at the developer console.
The browser (in my case: Edge) did receive a mono.wasm file, which is a WebAssembly and includes a .NET runtime environment. Thus, we can simply send .dll files to the browser and the Mono-Runtime is able to execute the code. (Like the .dlls, also visible in the screenshot above)
I uploaded the binaries + the index.html to my Web-Server. Feel free to visit the WebAssembly: https://www.indie-dev.at/Blazor/Example/ Remember, there is no IIS running on the server! What you see is already running on your client. However, if you want/need a .NET server backend as well, use the Blazor (ASP.NET Core Hosted) template.
Great, but what’s next?
The mono.wasm (.NET WebAssembly Runtime) is currently restricted to .NET Standard 2.0. Thus, what can be done is extremely limited. But what is Blazor currently aware of?
- A component model for building composable UI
- Forms and validation
- Dependency injection
And what Blazor will support
- Live reloading in the browser during development
- 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
- Publishing and app size trimming
Since this project is still in development and currently flagged as “experimental” we can’t expect too much. With that said, I still would like to sum a few things up to address the boundaries.
- Debugging is not supported
- Arbitrary Exceptions after compilation
- Intellisense nearly none-existing
- Threading seems to break the application (InFinite Loop)
- Tasks also seem to break the application (InFinite Loop)
- .NET Standard 2.0 (Few NuGet packages)
For me, Blazor is currently a small playground. Maybe in a few years we are able to build our first enterprise applications with it. But for now, it stays an experimental prototype as a proof of concept.