News

As .NET 6 Nears GA, Blazor WebAssembly Can Now Use Native Dependencies

Less than a month before .NET 6 ships, Microsoft announced Blazor WebAssembly apps can now use native dependencies, allowing developers to tap into native C code, for example, upon jumping through a few hoops.

Blazor WebAssembly -- part of ASP.NET Core -- is the client-side component of Blazor, which allows for web projects coded primarily in C# instead of the normal dependence on JavaScript. Its new native dependency functionality came with the release of .NET 6 Release Candidate 2 this week en route to General Availability status around the start of the Nov. 9 .NET Conf 2021 event.

While ASP.NET Core and Blazor are now basically in the polishing-up stage of the development cycle along with other components of .NET 6 -- which is already being used in production as a "go live" release -- some new features were announced by Daniel Roth, principal program manager for ASP.NET.

"Blazor WebAssembly apps in .NET 6 can now use native dependencies that have been built to run on WebAssembly," Roth said in an Oct. 12 announcement. "You can statically link native dependencies into the .NET WebAssembly runtime using the .NET WebAssembly build tools, the same tools that you can use in .NET 6 to ahead-of-time (AOT) compile your Blazor app to WebAssembly or to relink the runtime to remove unused features."

As an example, he showed how to add a simple C function to a Blazor WebAssembly app, which is done with Emscripten compiler toolchain technology, upon which the .NET WebAssembly build tools are based. The site for Emscripten says it's "a complete compiler toolchain to WebAssembly, using LLVM, with a special focus on speed, size, and the web platform."

So those build tools have to be installed via an elevated command prompt (or Visual Studio Installer), along with the latest .NET 6 SDK and the latest preview of Visual Studio 2022 (which as of this writing would be VS 2022 RC). Then developers need to add NativeFileReference items to a project file, after which they can p/invoke into the native code from their .NET code.

Developers can also use libraries, such as NuGet packages, that contain native dependencies after again jumping through some hoops.

"The files for the native dependencies should be built for WebAssembly and packaged in the browser-wasm architecture-specific folder," Roth said. "WebAssembly-specific dependencies won’t get referenced automatically and need to be referenced manually as a NativeFileReference. Package authors can choose to add the native references by including a .props file in the package with the references."

To detail that, Roth demonstrated a project using SkiaSharp, a cross-platform 2D graphics library for .NET based on the native Skia graphics library. That whole process can be duplicated in a Blazor WebAssembly sample app in the SkiaSharp repo.

Hello SkiaSharp
[Click on image for larger view.] Hello SkiaSharp (source: Microsoft).

The other new feature highlighted by Roth is an update to minimal API support. He explained in detail changes affecting parameter binding, OpenAPI, source code analysis and breaking changes resulting from APIs being renamed.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Using Local AI to Cut Copilot Usage-Based Billing Shock

    After being gobsmacked by the new billing plan using almost all my monthly credits in one or two days, I tried pushing some Copilot-style coding work onto local models in VS Code. What I found was less "free AI" and more "pick your pain": cloud charges on one side, heavy local resource use and long waits on the other.

  • .NET 11 Preview 5 Focuses on Performance, Productivity and Safer Code

    .NET 11 Preview 5 focuses on under-the-hood runtime performance gains, streamlined APIs and language features that reduce boilerplate, plus built‑in security checks and incremental ASP.NET Core and EF Core improvements aimed at everyday developer productivity.

  • VS Code 1.124 Focuses on Agent Autonomy and Parallel Sessions

    Microsoft's June 2026 VS Code update turns on Autopilot by default and adds background sending for agent sessions.

  • Developing Agentic Systems in .NET: From Concept to Code

    ZioNet founder Alon Fliess previews his Visual Studio Live! San Diego session on building true agentic systems in .NET -- covering the cognitive loop, MCP tool integration, multi-agent orchestration and enterprise hosting and governance with the Microsoft Agent Framework.

Subscribe on YouTube