Can't Call FromBinary() On a WASM File
See original GitHub issueHere are the steps to recreate the issue:
Go here, http://mbebenita.github.io/WasmExplorer/, and enter in this text for the “Wast”:
(module
(export "collatz" (func $_Z7collatzi))
(func $_Z7collatzi (param $0 i32) (result i32)
(local $1 i32)
(set_local $1
(i32.const 0)
)
(block $label$0
(br_if $label$0
(i32.lt_s
(get_local $0)
(i32.const 2)
)
)
(set_local $1
(i32.const 0)
)
(loop $label$1
(set_local $1
(i32.add
(get_local $1)
(i32.const 1)
)
)
(br_if $label$1
(i32.gt_s
(tee_local $0
(select
(i32.add
(i32.mul
(get_local $0)
(i32.const 3)
)
(i32.const 1)
)
(i32.div_s
(get_local $0)
(i32.const 2)
)
(i32.and
(get_local $0)
(i32.const 1)
)
)
)
(i32.const 1)
)
)
)
)
(get_local $1)
)
)
Press “Assemble” and then “Download”. You should have a test.wasm file in your Downloads folder.
Now, create a C# project that references the WebAssembly package. Move test.wasm to that project’s folder. Create this code in the Main() method:
Compile.FromBinary<dynamic>("collatz.wasm");
I get the following error: Unhandled Exception: WebAssembly.ModuleLoadException: At offset 124: Stream ended unexpectedly. —> System.IO.EndOfStreamException: Unable to read beyond the end of the stream. at System.IO.__Error.EndOfFile() at System.IO.BinaryReader.ReadByte() at WebAssembly.Reader.ReadByte() at WebAssembly.Reader.ReadVarInt32() at WebAssembly.Compile.FromBinary(Reader reader, Type instanceContainer, Type exportContainer) at WebAssembly.Compile.FromBinary[TExports](Stream input) — End of inner exception stack trace — at WebAssembly.Compile.FromBinary[TExports](Stream input) at WebAssembly.Compile.FromBinary[TExports](String path) at WasmToAssembly.Program.Main(String[] args)
However, if I go here - https://wasdk.github.io/wasmcodeexplorer/ - and load test.wasm, it shows up with no errors and the wast is generated correctly on the right-hand side.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
Fixed! This problem was the only thing preventing your code from running 😁
Are you able to grab the updated code from GitHub or do you need a new package?
Thanks for the report! Typically this error indicates that the “end” instruction is missing but the disassembly tool you linked showed it as present. I’ll take a deeper look in a day or two.