Two months ago, ASP.NET Core 3.0 was released with an updated version of the Blazor framework. This framework allows the building of interactive client-side web UI with .NET. Yesterday, Peter Huene, a staff research engineer at Mozilla shared his experience of using Wasmtime with .NET. He affirms that using this format will enable developers to programmatically load and execute WebAssembly code directly from their .NET programs.
Key benefits of using WebAssembly from .NET with Wasmtime
Share more code across platforms
Although .NET Core enables cross-platform use, developers find it difficult to use a native library as .Net Core requires native interop and a platform-specific build for each supported platform.
However, if the native library is compiled to WebAssembly, then the same WebAssembly module can be used across many different platforms and programming environments, including .NET. Thus a more simplified distribution of the library and applications will allow developers to share more codes across platforms.
Securely isolate untrusted code
According to Huene, “The .NET Framework attempted to sandbox untrusted code with technologies such as Code Access Security and Application Domains, but ultimately these failed to properly isolate untrusted code.” This resulted in Microsoft deprecating its use for sandboxing and removing it from .NET Core.
Huene asserts that since WebAssembly is designed for the web, its module will enable users to call the external explicitly imported function from a host environment and will also give access to only a region of memory given to it by the host. With WebAssembly, users can also leverage this design to sandbox code in a .NET program.
Improved interoperability with interface types
In August this year, WebAssembly’s interface types permitted users to run WebAssembly with many programming languages like Python, Ruby, and Rust. This interoperability reduced the amount of glue code which was necessary for passing complex types between the hosting application and a WebAssembly module.
According to Huene, if Wasmtime implements official support for interface types for .NET API in the future, it will enable a seamless exchange of complex types between WebAssembly and .NET.
Users have liked the approach of using WebAssembly from .NET with Wasmtime.
Cool way to compile other langues to Web Assembly and then run in .NET.
I really like what WASM is becoming & how different large companies are working on it. Still a long road ahead though.https://t.co/0mSXGNy1Ln
— Matt Ferderer 🍹 (@mattferderer) December 4, 2019
Calling Rust functions, compiled to Web Assembly, from dotnet Core 😯!
— Sean G. Wright (@seangwright) December 5, 2019
To know how Peter Huene used WebAssembly from .NET, check out his demonstrations on the Mozilla Hacks blog.