Blazor Update Boosts .NET/JavaScript Interoperability

Microsoft continues to churn out updates to its experimental Blazor technology for running C# code on the Web, with the latest boosting JavaScript interoperability.

Specifically, it easier handles sync and async .NET method calls from JavaScript, along with calling registered JavaScript async functions from .NET. This interoperability further belies opinions voiced by some developers that Blazor could deliver them from "the insanity of JavaScript" or foster "death to JavaScript." Microsoft has always shied away from such notions, insisting Blazor is just another tool that can be used in conjunction with JavaScript and other tech.

Even though it's just alpha-quality tech at this point, Blazor has stirred up tremendous interest in the .NET developer community, stealing the show during a recent keynote address at the Visual Studio Live! conference in Austin.

The experimental project -- developed on the ASP.NET section of GitHub -- is described as a .NET web framework using C#/Razor and HTML that runs in the browser with WebAssembly.

WebAssembly allows for compilation of high-level languages (C/C++/Rust/C# and so on) for deployment on the Web in both client and server applications.

Mozilla developer guidance describes it as: "a new type of code that can be run in modern Web browsers -- it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++ with a compilation target so that they can run on the Web. It is also designed to run alongside JavaScript, allowing both to work together."

As part of that WebAssembly/JavaScript working together feature, Blazor 0.4.0 -- just announced yesterday (June 7) -- has improved the calling of .NET methods from JavaScript code and vice-versa: calling async JavaScript functions from .NET.

Speaking of the former, the post says: "Blazor 0.4.0 makes it easy to call sync and async .NET methods from JavaScript. For example, you might call back into .NET when a JavaScript callback is triggered. While calling into .NET from JavaScript was possible with earlier Blazor releases the pattern was low-level and difficult to use. Blazor 0.4.0 provides simpler pattern with the new Blazor.invokeDotNetMethod and Blazor.invokeDotNetMethodAsync functions."

Speaking of the latter, it says: "With Blazor 0.4.0 you can now call and await registered JavaScript async functions like you would an async .NET method using the new RegisteredFunction.InvokeAsync method."

Other improvements in v0.4.0 -- coming just a month after 0.3.0 was released -- include:

  • Add event payloads for common event types
  • Use camelCase for JSON handling
  • Automatic import of core Blazor namespaces in Razor
  • Send and receive binary HTTP content using HttpClient
  • Templates run on IIS Express by default with autobuild enabled
  • Bind to numeric types

Full release notes can be found here, posted by Daniel Roth, who reminded everybody, "Please note that this is an alpha quality release and is not suitable for production applications."

Many in the developer community can hardly wait. "Is debugging support near?" asked one developer in a comment to Roth's announcement post. No answer yet.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


Subscribe on YouTube