Create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.
Create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.
[!NOTE] WebAssembly 3.0 is supported. WASM files that use features newer than the ratified 3.0 standard may encounter errors.
A library able to create, read, modify, write, execute, and DLL-convert WebAssembly (WASM) files from .NET-based applications.
Available on NuGet at https://www.nuget.org/packages/WebAssembly.
WebAssembly.Module class to create, read, modify, and write WebAssembly (WASM) binary files.Module.ReadFromBinary reads a stream into an instance, which can then be inspected and modified through its properties.WriteToBinary on a module instance writes binary WASM to the provided stream.WebAssembly.Runtime.Compile class to execute WebAssembly (WASM) binary files using the .NET JIT compiler or convert it to a .NET DLL.If you hit a problem, write a bug report with the repro steps and links to any files needed.
…The saving process uses the PersistedAssemblyBuilder feature introduced in .NET 9. Aided by MetadataLoadContext, this example produces a DLL for .NET 8.
…To use the new DLL, you directly reference it in your .csproj.
bin\HelloWorld.dll
Once the DLL reference is in place, you can access it just like any other .NET library.
var helloWorld = new Converted.HelloWorld((module, field) =>
{
// Imports are defined by the original WASM and must be supplied by you.
if (module == "env" && field == "sayc")
return new FunctionImport(new Action(raw => Console.Write((char)raw)));
throw new Exception($"Unknown import: {module} {field}");
});
// You can directly access anything exported by the WASM.
var result = helloWorld.main();No open issues yet, or sync has not completed.