Can't print DateTimeOffset from exported function unless called from Main before
See original GitHub issueOk I spent pretty much entire day today trying to figure out what’s going on here because this bug reproduces in pretty weird ways, but now I’m giving up and going to need some help please. @SteveSandersonMS.
Here’s reasonably minimal sample that at least prints a useful error message: https://gist.github.com/RReverser/db10fc4dfe039630eb24821e1d619bf7 (in other instances I ran into, it just crashes)
Error:
C:\Users\me\Documents\MyFirstWasiApp> dotnet build && node tester.mjs
MSBuild version 17.5.1+f6fdcf537 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
MyFirstWasiApp -> C:\Users\me\Documents\MyFirstWasiApp\bin\Debug\net7.0\MyFirstWasiApp.dll
MyFirstWasiApp -> C:\Users\me\Documents\MyFirstWasiApp\bin\Debug\net7.0\MyFirstWasiApp.wasm
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.51
(node:9388) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
started
[wasm_trace_logger] Process terminated.
[wasm_trace_logger] Encountered infinite recursion while looking up resource 'Arg_DllNotFoundException' in System.Private.CoreLib. Verify the installation of .NET is complete and does not need repairing, and that the state of the process has not become corrupted.
wasm://wasm/021e6e66:1
RuntimeError: unreachable
at wasm://wasm/021e6e66:wasm-function[7608]:0x40426c
at wasm://wasm/021e6e66:wasm-function[1804]:0x17e17a
at wasm://wasm/021e6e66:wasm-function[1871]:0x184647
at wasm://wasm/021e6e66:wasm-function[448]:0xbf9dc
at wasm://wasm/021e6e66:wasm-function[395]:0xbbf59
at wasm://wasm/021e6e66:wasm-function[323]:0x65c17
at wasm://wasm/021e6e66:wasm-function[322]:0x61cdb
at wasm://wasm/021e6e66:wasm-function[6283]:0x365c2f
at wasm://wasm/021e6e66:wasm-function[3064]:0x20f893
at wasm://wasm/021e6e66:wasm-function[3062]:0x20f661
Node.js v20.0.0
What’s weird is, if I uncomment printing DateTimeOffset.UnixEpoch
(I chose it just because it’s a constant, to reduce repro and not depend on WASI time) in Main
, then both that one and the one in HelloWorld
work fine, but if it’s commented out (or, as in my original project, doesn’t exit), then logging instances of DateTimeOffset
crashes everywhere else as well.
Judging by this message and the observed behaviour, I suspect there is some lazy initialisation happening that only loads DLLs if they are needed by Main
function but not other exports? Not sure what to make of it or how to fix it.
Issue Analytics
- State:
- Created 3 months ago
- Comments:6 (2 by maintainers)
And also WasiAfterRuntimeLoaded doesn’t work:
And then there are missing symbols for all those utils like mono_wasm_invoke_method.
It just seems a lot less mature than Wasi.Sdk for now which at least does work today.
Right, just double-checked and the problem with .NET 8 is that no matter what I do, I can’t get my own imports/exports to show up in generated Wasm.