john k
john k

Reputation: 6615

How to call dll methods in a node.js application? (Parameter count mismatch)

I am trying to use a c# .dll from my node.js application. I am using the edge-js library to accomplish this.

I am able to load the dll but cannot manage to call its methods. The error I am getting is

Error: Parameter count mismatch. at anonymous:1:55

If anyone can explain how Edge bindings/parameter passing works, it would be appreciated.

dll code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics;

namespace PortableClassLibrary1
{
    public class Class1
    {
        public String helloworld(){
            Debug.WriteLine("Hello dll world");  
            return("Hello dll World!");
        }

    }
}

Here is my (simplifed) node.js code:

"use strict";
const express = require("express");
const router = express.Router();
const { Console } = require("console");

router.get("/", (req, res) => {
 var edge = require("edge-js");
  var helloDll = edge.func({
    assemblyFile: "bin/PortableClassLibrary1.dll",
    typeName: "PortableClassLibrary1.Class1",
    methodName: "helloworld",
  });
  helloDll(null, function (error, result) {
    if (error) throw error;
    console.log(result);
  });

});


module.exports = router;

I have also tried synchronous calls:

  var returnResult = helloDll(true);
  var returnResult = helloDll(null, true);

with the same results.

I looked at these links but they did not help.

So how about it? Anyone know how to call .dll methods using edge-js?

Upvotes: -1

Views: 4389

Answers (1)

Jay P
Jay P

Reputation: 119

"helloworld" method in the dll should return a Task and accept an input parameter.

I have modified the code as below and it worked for me.

    public async Task<object> helloworld(dynamic input)
    {
        Debug.WriteLine("Hello dll world");
        // Ignore the compiler warning about await keyword as this just a demo code..
        return "Hello from.NET world !!";
    }

Upvotes: 1

Related Questions