Open JamieMagee opened 2 years ago
When trying to do a Directory.GetFiles call using Node.js as my runtime I get a System.EntryPointNotFoundException: SystemNative_OpenDir exception.
Directory.GetFiles
Node.js
System.EntryPointNotFoundException: SystemNative_OpenDir
Reading a specific file works okay.
$ node --version v18.6.0 $ dotnet --list-sdks 3.1.421 [C:\Program Files\dotnet\sdk] 6.0.100-rc.1.21463.6 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk] 6.0.107 [C:\Program Files\dotnet\sdk] 6.0.302 [C:\Program Files\dotnet\sdk] 7.0.100-preview.5.22307.18 [C:\Program Files\dotnet\sdk]
```c# Console.WriteLine("Hello, World!"); var content = File.ReadAllText("/sandbox/sandbox.txt"); Console.WriteLine(content); var files = Directory.GetFiles("/sandbox"); foreach (var file in files) { Console.WriteLine(file); } ```
```js import { readFile } from 'node:fs/promises'; import { WASI } from 'wasi'; import { argv, env } from 'node:process'; const wasi = new WASI({ args: argv, env, preopens: { '/sandbox': process.cwd(), } }); const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; const wasm = await WebAssembly.compile( await readFile(new URL('./dotnet-wasm.wasm', import.meta.url)) ); const instance = await WebAssembly.instantiate(wasm, importObject); wasi.start(instance); ```
``` $ node --experimental-wasi-unstable-preview1 .\index.mjs (node:43600) ExperimentalWarning: WASI is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) Hello, World! Hello world Unhandled Exception: System.EntryPointNotFoundException: SystemNative_OpenDir at Interop.Sys.OpenDir(String path) at System.IO.Enumeration.FileSystemEnumerator`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateDirectoryHandle(String path, Boolean ignoreNotFound) at System.IO.Enumeration.FileSystemEnumerator`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Init() at System.IO.Enumeration.FileSystemEnumerator`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(String directory, Boolean isNormalized, EnumerationOptions options) at System.IO.Enumeration.FileSystemEnumerable`1.DelegateEnumerator[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(FileSystemEnumerable`1 enumerable, Boolean isNormalized) at System.IO.Enumeration.FileSystemEnumerable`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized) at System.IO.Enumeration.FileSystemEnumerable`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(String directory, FindTransform transform, EnumerationOptions options) at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options) at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) at System.IO.Directory.GetFiles(String path, String searchPattern, EnumerationOptions enumerationOptions) at System.IO.Directory.GetFiles(String path) at Program.
When trying to do a
Directory.GetFiles
call usingNode.js
as my runtime I get aSystem.EntryPointNotFoundException: SystemNative_OpenDir
exception.Reading a specific file works okay.
Program.cs
```c# Console.WriteLine("Hello, World!"); var content = File.ReadAllText("/sandbox/sandbox.txt"); Console.WriteLine(content); var files = Directory.GetFiles("/sandbox"); foreach (var file in files) { Console.WriteLine(file); } ```
index.mjs
```js import { readFile } from 'node:fs/promises'; import { WASI } from 'wasi'; import { argv, env } from 'node:process'; const wasi = new WASI({ args: argv, env, preopens: { '/sandbox': process.cwd(), } }); const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; const wasm = await WebAssembly.compile( await readFile(new URL('./dotnet-wasm.wasm', import.meta.url)) ); const instance = await WebAssembly.instantiate(wasm, importObject); wasi.start(instance); ```
Output
``` $ node --experimental-wasi-unstable-preview1 .\index.mjs (node:43600) ExperimentalWarning: WASI is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) Hello, World! Hello world Unhandled Exception: System.EntryPointNotFoundException: SystemNative_OpenDir at Interop.Sys.OpenDir(String path) at System.IO.Enumeration.FileSystemEnumerator`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateDirectoryHandle(String path, Boolean ignoreNotFound) at System.IO.Enumeration.FileSystemEnumerator`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Init() at System.IO.Enumeration.FileSystemEnumerator`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(String directory, Boolean isNormalized, EnumerationOptions options) at System.IO.Enumeration.FileSystemEnumerable`1.DelegateEnumerator[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(FileSystemEnumerable`1 enumerable, Boolean isNormalized) at System.IO.Enumeration.FileSystemEnumerable`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized) at System.IO.Enumeration.FileSystemEnumerable`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(String directory, FindTransform transform, EnumerationOptions options) at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options) at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) at System.IO.Directory.GetFiles(String path, String searchPattern, EnumerationOptions enumerationOptions) at System.IO.Directory.GetFiles(String path) at Program.