You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-2Lines changed: 65 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,8 @@
5
5
> Only WebAssembly 1.0 is supported!
6
6
> Most WASM files target a higher version and will encounter errors if you try to load them with WebAssembly for .NET.
7
7
8
-
A library able to create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.
8
+
A library able to create, read, modify, write, execute WebAssembly (WASM) files from .NET-based applications.
9
+
It can also convert WASM files to .NET DLLs.
9
10
*Execution does not use an interpreter or a 3rd party library:*
10
11
WASM instructions are mapped to their .NET equivalents and converted to native machine language by the .NET JIT compiler.
11
12
@@ -17,10 +18,11 @@ Available on NuGet at https://www.nuget.org/packages/WebAssembly .
17
18
-`Module.ReadFromBinary` reads a stream into an instance, which can then be inspected and modified through its properties.
18
19
- Most WASM files use post-1.0 features and will experience errors when you try to load them.
19
20
-`WriteToBinary` on a module instance writes binary WASM to the provided stream.
20
-
- Use the `WebAssembly.Runtime.Compile` class to execute WebAssembly (WASM) binary files using the .NET JIT compiler.
21
+
- Use the `WebAssembly.Runtime.Compile` class to execute WebAssembly (WASM) binary files using the .NET JIT compiler or convert it to a .NET DLL.
21
22
- Most WASM files have many imports and exports--you'll need to cover these yourself.
22
23
- This should work for most WASM 1.0 files, but spec compliance is not perfect.
23
24
- This will not work for any newer-than-1.0 files
25
+
- Saving to a DLL requires .NET 9 or higher and has several additional steps.
24
26
25
27
You're welcome to report a bug if you can share a WASM file that has a problem, but no one is actively working on this project so a fix may not come.
26
28
@@ -102,7 +104,68 @@ public abstract class Sample
102
104
// Sometimes you can use C# dynamic instead of building an abstract class like this.
103
105
publicabstractintDemo(intvalue);
104
106
}
107
+
```
108
+
## Sample: Convert a WASM file to a .NET DLL
109
+
110
+
> [!NOTE]
111
+
> This feature is experimental.
112
+
113
+
The saving process uses the [PersistedAssemblyBuilder](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.persistedassemblybuilder.-ctor) feature introduced in .NET 9.
114
+
Aided by [MetadataLoadContext](https://www.nuget.org/packages/System.Reflection.MetadataLoadContext), this example produces a DLL for .NET Standard 2.0.
115
+
116
+
```C#
117
+
varresolver=newPathAssemblyResolver([
118
+
// A core DLL containing System.String and other basic features:
0 commit comments