How to call functions in a C# dll file from a node.js file
Asked Answered
H

2

6

**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?

Harrietharriett answered 27/7, 2015 at 0:50 Comment(1)
that works with C and C++ not C# tho, at least to my understandingHarrietharriett
E
3

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.

Emelyemelyne answered 2/8, 2020 at 13:14 Comment(0)
G
2

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.

Gantrisin answered 27/7, 2015 at 0:54 Comment(2)
Thanks! I saw something earlier about edge.js, do you know anything about it?Harrietharriett
@Harrietharriett - I don't know anything about it.Gantrisin

© 2022 - 2024 — McMap. All rights reserved.