使用edge.js調用.dll文件 第二次補充:
edgejs按我我的理解,是一個容許經過Node去調用 C# 的一個庫。由於最近的項目須要才接觸的。html
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace print { public class Print { public async Task<object> getPrinter(Object input) { String [] printers = (String[])input; String Printer = ""; String TagPrinter = ""; String Scanner = ""; for (int i = 0; i < printers.Length; i++) { Printer = printers[0].ToString(); TagPrinter = printers[1].ToString(); Scanner = printers[2].ToString(); } usePrinter(Printer); useTagPrinter(TagPrinter); useScanner(Scanner); return null; } public static void usePrinter(string printer) { Console.WriteLine(printer); } public static void useTagPrinter(string printer) { Console.WriteLine(printer); } public static void useScanner(string printer) { Console.WriteLine(printer); } } }
///index.js文件代碼 var edge = require('edge'); var url = require('url'); var util = require('util'); var getPrinter = edge.func('E:/workspace/Csharpworkspace/nodecs/print.dll'); var input = ['Printer','TagPrinter','Scanner']; getPrinter(input,function(error,result){ if(error) throw error; console.log(result); });
C# 要用忽然學了兩天 :-) ,額~而後報錯的信息以下。node
E:\workspace\Csharpworkspace\nodecs\node_modules\edge\lib\edge.js:169 return edge.initializeClrFunc(options); ^ Error: 未能從程序集「print, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null」中加載類型「print.Startup」。 at Error (native) at Object.exports.func (E:\workspace\Csharpworkspace\nodecs\node_modules\edge\lib\edge.js:169:17) at Object.<anonymous> (E:\workspace\Csharpworkspace\nodecs\index.js:3:23) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7)
請問這個是什麼問題呢?npm
補充:覺得有多是nod找不到.dll文件,又增長了bootstrap
var url = require('url'); var util = require('util');
以上是我以前發佈的一個提問,一段時間以後我在另外一位大神的博客找到了答案,以及如何解決的方案。在這裏作一個記錄。
大神的博客在這裏http://www.cnblogs.com/sfcyyc...async
///index.js文件代碼 var edge = require('edge'); var input = ['Printer','TagPrinter','Scanner']; var getPrinter = edge.func({ assemblyFile:"E:/workspace/Csharpworkspace/nodecs/print.dll", typeName:"print.Print", methodName: "getPrinter" }); getPrinter(input,function(err,result) { if (err) throw err; console.log(result); });
這樣應該是能夠完成的,根據本身的具體狀況,方法大同小異。[逃..]ui