Hi,
I having problems referencing a external DLL from edge. I've added the DLL to the .NET GAL but I still cannot reference from within edge.
var edge = require('edge');
var hello = edge.func(function () {/*
var listCertificates = edge.func(function() {/*
#r "System.dll"
#r "BouncyCastle.Crypto.dll"
using Org.BouncyCastle.Pkcs;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.OpenSsl;
using System.Text;
using System.IO;
async (data) =>
{
//Requested Certificate Name
X509Name name = new X509Name("CN=Client Cert, C=NL");
*/});
This is the error!
Uncaught System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Unable to compile C# code.
----> Errors when compiling as a CLR library:
error CS0006: Metadata file 'BouncyCastle.Crypto.dll' could not be found
----> Errors when compiling as a CLR async lambda expression:
error CS0006: Metadata file 'BouncyCastle.Crypto.dll' could not be found
at EdgeCompiler.CompileFunc(IDictionary`2 parameters)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ClrFunc.Initialize(Handle<v8::Value>* , Arguments* args) in c:\edge-master-2\edge-master\src\clrfunc.cpp:line 91
You mean you added it to GAC, not GAL, right? What is the output of gacutil -l BouncyCastle.Crypto
?
Yes sorry GAC! Output from gacutil -l BouncyCastle.Crypto
is:
C:\GACkey>gacutil -l BouncyCastle.Crypto
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.17626
Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
BouncyCastle.Crypto, Version=1.7.4114.6375, Culture=neutral, PublicKeyToken=aa
5196b1909f504b, processorArchitecture=MSIL
Number of items = 1
Is there anything Im missing here?
Nothing jumps at me. Can you try creating a simple Hello, world C# app and compile it from command line while referencing this dll?
csc.exe /r BouncyCastle.Crypto.dll hello.cs
OK So I deleted the BouncyCastle.Crypto.dll from the GAC then created a simple Hello, world C# app, I copied the BouncyCastle.Crypto.dll into the same directory as the hello.cs file then did this:
csc.exe /reference:BouncyCastle.Crypto.dll Program.cs
It compiled OK and the produces a .exe which ran OK and it referenced the BouncyCastle.Crypto.dll as I expected.
I then copied the BouncyCastle.Crypto.dll
into the my node-webkit
folder and ran my node-webkit/edge app and it worked.
So, should I not be able to specifically reference the location of the BouncyCastle.Crypto.dll
like I do on the command line? If so where should I put them to make them accessible to my node-webkit/node.js/edge app?
Try in the same directory as the node.exe running your app.
Yes - as per my previous comment this works.
The question is, is it possible to reference the file from a "lib" directory ?
The #r
should accept a fully qualified file name. Alternatively, you can also specify reference assembles using this syntax:
var mycsharpcode = function () {/*
.... the C# goes here
*/};
var myfunc = edge.func({
source: mycsharpcode,
references: [ 'c:\\mydirectory\\BouncyCaste.dll' ]
});
The full reference file system location can be computed using __dirname.
@tjanczuk , I did as you said:
var path = "C:\\Program Files\\nodejs";
var test = edge.func({
assemblyFile: "APITest.dll",
typeName: "APITest.Startup",
methodName: "Invoke",
references: [
(path + "\\dll\\MyApp.Entity.dll")
]
});
The dll folder is in the same directory as node.exe.
It also throw the error when call function test
: ...Could not load file or assembly 'MyApp.Entity ...
It is ok if MyApp.Entity.dll
is in the same directory as node.exe. But, it is not very nice.
Which version of edge and edge-cs are you using? Edge 0.7.12 and edge-cs 0.2.4 make this scenario work after fixing https://github.com/tjanczuk/edge-cs/commit/7b510b3b3d5bcac3f225c6be49cfc61c1ec1a1aa.
From: Abel [[email protected]]
Sent: Friday, July 05, 2013 1:39 AM
To: tjanczuk/edge
Cc: Tomasz Janczuk
Subject: Re: [edge] Referencing external 3rd party DLL (#62)
@tjanczukhttps://github.com/tjanczuk , I did as you said:
var path = "C:\Program Files\nodejs";
var test = edge.func({
assemblyFile: "APITest.dll",
typeName: "APITest.Startup",
methodName: "Invoke",
references: [
(path + "\dllMyApp.Entity.dll")
]
});
The dll folder is in the same directory as node.exe.
It also throw the error when call function test: ...Could not load file or assembly 'MyApp.Entity ...
It is ok if MyApp.Entity.dll is in the same directory as node.exe. But, it is not very nice.
—
Reply to this email directly or view it on GitHubhttps://github.com/tjanczuk/edge/issues/62#issuecomment-20506918.
@tjanczuk , sorry about that. It was my mistake. My dll MyApp.Entity.dll
had a mapping file. They should be under the folder bin
in .NET project. So, using edge.js, it should under the folder NodeJS
next to node.exe
.
Im too getting same error pls someone help
var edge = require('edge');
var helloWorld = edge.func({assemblyFile:'MR6100Api.dll',typeName:'MR6100Api.MR6100Api',
methodName: 'isNetWorkConnect',
references: [
("C:\\Users\\killer\\Documents\\hello\\sample\\MR6100Api.dll")
]
});
helloWorld('127.0.0.1', function (error, result) {
if (error) throw error;
console.log(result);
});
Exception
return edge.initializeClrFunc(options);
^
Error: Could not load file or assembly 'file:///C:\Users\killer\Documents\hello\sample\MR6100Api
.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
at Error (native)
at Object.exports.func (C:\Users\killer\Documents\hello\sample\node_modules\edge\lib\edge.js
:154:17)
at Object.<anonymous> (C:\Users\killer\Documents\hello\sample\server.js:3:23)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
please help me out
I have done strong name snk for the dll and then added the dll to GAC. It worked perfect.
I have also added the dll to nodejs exe directory.
So far did follow your instruction ebove. It did not work.
Would be nice if you would create a documentation more clearer than fragmented information.
I saw your first page documentation in github, which does not cover external dll integration.
It would be a big help if you would explain step by step how to work with external dll and c# code from associated dll.
Most helpful comment
I have done strong name snk for the dll and then added the dll to GAC. It worked perfect.
I have also added the dll to nodejs exe directory.
So far did follow your instruction ebove. It did not work.
Would be nice if you would create a documentation more clearer than fragmented information.
I saw your first page documentation in github, which does not cover external dll integration.
It would be a big help if you would explain step by step how to work with external dll and c# code from associated dll.