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 摘要。