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 print DateTimeOffset from exported function unless called from Main before

See original GitHub issue

Ok 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:closed
  • Created 3 months ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RReversercommented, Jun 27, 2023

And also WasiAfterRuntimeLoaded doesn’t work:

/home/rreverser/.dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/8.0.0-preview.5.23280.8/Sdk/WasiApp.Native.targets(465,26): error MSB4012: The expression “-D WASI_AFTER_RUNTIME_LOADED_DECLARATIONS=”@(WasiAfterRuntimeLoadedDeclarations, ’ ')“” cannot be used in this context. Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists. [/home/rreverser/spacetime-web/api/module_templates/cs/StdbModule.csproj]

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.

0reactions
RReversercommented, Jun 27, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing with DateTime and DateTimeOffset · Issue #1949
I think it should be fine if you are documenting your time information input and output at the client based on time zones...
Read more >
Exporting a function from an already exported function
js , the "main" function as I like to call it. initCalendar() is exported from events.js using the export keyword : export const...
Read more >
Instantiating a DateTimeOffset object
Read how to instantiate (make an instance of) a DateTimeOffset object in .NET. Learn about date & time literals, constructors, implicit type ...
Read more >
datetime (Transact-SQL) - SQL Server
Defines a date that is combined with a time of day with fractional seconds that is based on a 24-hour clock. ... Use...
Read more >
datetime — Basic date and time types
These tzinfo objects capture information about the offset from UTC time, the time zone name, and whether daylight saving time is in effect....
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