question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't Call FromBinary() On a WASM File

See original GitHub issue

Here 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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanLamanskycommented, Aug 16, 2017

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?

1reaction
RyanLamanskycommented, Aug 15, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fail to load a wasm file in a Web application
pkg/test_wasm.js'; function run { // use the function ex_function1 here } init().then(run). You include your index.js in your HTML file
Read more >
Can't run wasm app.
Here the issue is we need the wasm binary - it's in a side file with suffix .wasm. You can either load it...
Read more >
In wasm-bindgen 0.2.84 version, webpack cannot generate ...
js and wasm file will be generated in the project root; It is expected behavior. When i change the wasm-bindgen version to 0.2.84...
Read more >
Troubleshooting
Solution: delete the old one and keep the one that was added by Gogs only. Cannot call 'git' command by Gogs. Error: repo.NewRepoContext(fail...
Read more >
Read data from binary file - MATLAB fread
Use fopen to open the file and obtain the fileID value. When you finish reading, close the file by calling fclose(fileID) . A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found