Importing `node-api-dotnet` into node into a dotnet app
@jasongin がすでに取り組んでいます。
2024年7月24日 から。
評価
この issue はまだ評価されていません。
説明
The use case here is to create a runtime "script editor" that uses javascript/typescript as the language.
So the goal is:
- Running in dotnet host program
- User writes javascript that can interop with net objects
- Javascript is executed by the dotnet side.
I'm having issues calling the javascript import of node-api-dotnet when it's running inside the host process. Here's a reproducible example, where the TEST_MS flag just makes sure it does work with the simple ms package.
//#define TEST_MS
// See https://aka.ms/new-console-template for more information
using Microsoft.JavaScript.NodeApi;
using Microsoft.JavaScript.NodeApi.Runtime;
using System.Reflection;
Console.WriteLine("Hello, World!");
string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
File.WriteAllText(Path.Combine(baseDir, "package.json"), $"{{\"type\":\"module\"}}");
NodejsPlatform platform = new NodejsPlatform(Path.Combine(baseDir, "native", "win-x64", "libnode.dll"));
NodejsEnvironment env = platform.CreateEnvironment(baseDir);
await env.RunAsync(async () =>
{
#if TEST_MS
JSValue console = JSValue.CreateObject();
console.SetProperty("info", JSValue.CreateFunction("info", (args) =>
{
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine(args[i].GetValueExternalOrPrimitive()!.ToString());
}
return JSValue.Undefined;
}));
JSValue.Global.SetProperty("console", console);
JSValue.RunScript("const ms = require(\"C:/node_modules/ms\"); " +
"console.info(\"data\", ms(1231234));");
#else
JSValue.RunScript("const dotnet = require(\"C:/node_modules/node-api-dotnet\");");
Console.WriteLine("Finished.");
#endif
});
The exception I get here is:
Unhandled Exception: System.EntryPointNotFoundException: Arg_EntryPointNotFoundExceptionParameterizedNoLibrary, napi_create_string_utf16
at System.Runtime.InteropServices.NativeLibrary.GetSymbol(IntPtr, String, Boolean) + 0x57
at Microsoft.JavaScript.NodeApi.Runtime.NodejsRuntime.CreateString(JSRuntime.napi_env, ReadOnlySpan`1, JSRuntime.napi_value&) + 0x62
at Microsoft.JavaScript.NodeApi.JSValue.CreateStringUtf16(String) + 0x72
at Microsoft.JavaScript.NodeApi.JSValue.op_Implicit(String) + 0x15
at Microsoft.JavaScript.NodeApi.DotNetHost.NativeHost.InitializeModule(JSRuntime.napi_env, JSRuntime.napi_value) + 0x435
Which is the same when using await env.ImportAsync("C:/node_modules/node-api-dotnet/net8.0", null, true);
It did occur to me that the Microsoft.JavaScript.NodeApi.dll exists in both the dotnet project and the node module here. Any ideas on how to resolve this?
- 主要言語
- C#
- スター
- 783
- フォーク
- 80
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/node-api-dotnet のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
microsoft/node-api-dotnet#484 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/node-api-dotnet#481 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
microsoft/node-api-dotnet#486 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
microsoft/node-api-dotnet#483 · コメント 1 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
microsoft/node-api-dotnet#479 ·
microsoft/node-api-dotnet の issue をすべて見る
似ている issue
-
bug P3
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
nightscout/nocturne#1908 ·
メンテナーはふだん 1 日以内に返信
-
bug documentation Needs: Triage :mag:
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
WPF: each page's `Title` overwrites the window title, and returning to a page does not restore itオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
agentic-workflows area/Docs partner/agentic-workflows
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jamesmontemagno/tiny-clips#378 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信