【发布时间】:2021-01-01 13:28:37
【问题描述】:
我正在尝试使用我的 node.js 应用程序中的 c# .dll。我正在使用edge-js library 来完成此操作。
我能够加载 dll,但无法调用它的方法。 我得到的错误是
错误:参数计数不匹配。 匿名时间:1:55
如果有人能解释边缘绑定/参数传递的工作原理,将不胜感激。
dll代码:
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!");
}
}
}
这是我的(简化的)node.js 代码:
"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;
我也尝试过同步调用:
var returnResult = helloDll(true);
var returnResult = helloDll(null, true);
结果相同。
我查看了这些链接,但没有帮助。
-
How can I use ActiveX DLL in c# code snippet for node js using edge js?
-
Can't call method inside C# DLL from node service using Edge.js
那么怎么样呢?有人知道如何使用 edge-js 调用 .dll 方法吗?
【问题讨论】:
-
您正在调用实例方法。您需要一个实例来调用它(这可能是缺少的参数) 不知道它是如何与这个库一起工作的。尝试将其设为静态方法,看看会发生什么
-
我将其设为静态并得到不同的错误:System.InvalidOperationException 无法访问 CLR 方法以通过反射进行包装。确保它是一个公共实例方法