Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Crash when returning a IntPtr when dynamically invoke .NET APIs

未關閉
#459 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
42/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
csharp, node.js
領域
api, backend

研究方向

從 src/NodeApi/JSValue.cs:609 開始,使用所示 Node.js REPL 範例中的 NativeLibrary.GetMainProgramHandle() 重現該失敗。將堆疊追蹤與其他回傳 IntPtr 的 API 進行比較;當這些動態呼叫不再當機並成功回傳結果時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

Hi!

When I try to invoke dynamically an API which returns an IntPtr (e.g. GetMainProgramHandle()) the process crashes:

C:\Users\xc3ll>node
Welcome to Node.js v16.15.1.
Type ".help" for more information.
> const test = require('node-api-dotnet');
> handle = test.System.Runtime.InteropServices.NativeLibrary.GetMainProgramHandle()


Microsoft.JavaScript.NodeApi.JSException: Invalid argument: Error in DefineProperties at D:\a\_work\1\s\src\NodeApi\JSValue.cs:609
   at REPL72:1:60
   at Script.runInThisContext (node:vm:129:12)
   at REPLServer.defaultEval (node:repl:566:29)
   at bound (node:domain:421:15)
   at REPLServer.runBound [as eval] (node:domain:432:12)
   at REPLServer.onLine (node:repl:893:10)
   at REPLServer.emit (node:events:539:35)
   at REPLServer.emit (node:domain:475:12)
   at REPLServer.Interface._onLine (node:readline:487:10)
   at REPLServer.Interface._line (node:readline:864:8)
   at Microsoft.JavaScript.NodeApi.JSValue.<>c__DisplayClass114_0.<DefineProperties>b__0(String _, ReadOnlySpan`1 descriptorsPtr)
   at Microsoft.JavaScript.NodeApi.JSValue.ToUnmanagedPropertyDescriptors(String name, IReadOnlyCollection`1 descriptors, UseUnmanagedDescriptors action)
   at Microsoft.JavaScript.NodeApi.JSValue.DefineProperties(JSPropertyDescriptor[] descriptors)
   at Microsoft.JavaScript.NodeApi.JSError.CreateErrorValueForException(Exception exception, String& message)
   at Microsoft.JavaScript.NodeApi.JSError.ThrowError(Exception exception)
   at Microsoft.JavaScript.NodeApi.JSValue.InvokeCallback[TDescriptor](napi_env env, napi_callback_info callbackInfo, JSValueScopeType scopeType, Func`2 getCallbackDescriptor)
   at Microsoft.JavaScript.NodeApi.JSValue.InvokeJSMethod(napi_env env, napi_callback_info callbackInfo)


I tested it with other functions and the result is the same.

主要語言
C#
星號
783
分支
80
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/node-api-dotnet 的其他 Issue

查看 microsoft/node-api-dotnet 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。