**I created a C# dll file that contains functions that returns some values, and I am trying to call these functions from a node.js file to get those values. Please how do I go about this?
I believe the Edge.js - Run .NET and Node.js code in-process on Windows, macOS, and Linux is what you need.
By using Edge.js
, we can write the following JavaScript codes that invoke existing C# programs.
var clrMethod = edge.func({
assemblyFile: 'My.Edge.Samples.dll',
typeName: 'Samples.FooBar.MyType',
methodName: 'MyMethod' // This must be Func<object,Task<object>>
});
Or
var clrMethod = edge.func('My.Edge.Samples.dll');
Or
var add7 = edge.func(require('path').join(__dirname, 'add7.csx'));
The above three sample codes are all copy/pasted from their GitHub home page.
The documentation for how to implement a native code nodejs addon is here: Node.js v0.12.7 Addons and there are numerous examples included in that documentation.
More specific discussion of doing an addon in C# here: Using a .NET DLL in Node.js / serverside javascript and .net native extension for node.js
I can imagine it gets a bit tricky trying to hook up two garbage collected languages since automatic garbage collection probably isn't completely possible both ways.
© 2022 - 2024 — McMap. All rights reserved.