microsoft / microsoft/node-api-dotnet
Crash when returning a IntPtr when dynamically invoke .NET APIs
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 783
- Forks
- 80
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/NodeApi/JSValue.cs:609 and reproduce the failure with NativeLibrary.GetMainProgramHandle() from the shown Node.js REPL example. Compare the stack trace with other IntPtr-returning APIs; done means these dynamic invocations no longer crash and return their results successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100