News

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 at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube