Skip to content

Crash when returning a IntPtr when dynamically invoke .NET APIs #459

@X-C3LL

Description

@X-C3LL

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions