Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails out of the box with error 0x80070002 #3

Closed
rktect opened this issue Mar 20, 2018 · 23 comments
Closed

Fails out of the box with error 0x80070002 #3

rktect opened this issue Mar 20, 2018 · 23 comments

Comments

@rktect
Copy link

rktect commented Mar 20, 2018

I believe typically this is a file not found error - but I'm getting this running this sample:

module.js:672 return process.dlopen(module, path._makeLong(filename)); ^ Error: Call to coreclr_create_delegate() for G failed with a return code of 0x80070002. at Object.Module._extensions..node (module.js:672:18) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at Object.<anonymous> (D:\dev\code\edge-js-quick-start-master\edge-js-quick-start-master\node_modules\edge-js\lib\edge.js:53:8) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32)

Any ideas how to resolve this?

@rktect
Copy link
Author

rktect commented Mar 20, 2018

If I comment out the line:
process.env.EDGE_APP_ROOT = baseNetAppPath;

then I get past the above problem. But then is has a problem finding the ExternalLibrary reference:
return edge.initializeClrFunc(options); ^ Error: Could not load file or assembly 'ExternalLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. at Object.exports.func (d:\dev\code\edge-js-quick-start-master\edge-js-quick-start-master\node_modules\edge-js\lib\edge.js:178:17) at Object.<anonymous> (d:\dev\code\edge-js-quick-start-master\edge-js-quick-start-master\main.js:30:22) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Function.Module.runMain (module.js:684:10) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3

Progress but still not there.
BTW I'm stuck on a similar problem with a custom library I've made. Just can't get it to reference it properly.

@rktect
Copy link
Author

rktect commented Mar 20, 2018

Note I tried manually setting the reference:
var getAppDomainDirectory = edge.func({ assemblyFile: baseDll, typeName: 'QuickStart.Core.LocalMethods', methodName: 'GetAppDomainDirectory', references: [ ("D:/dev/code/edge-js-quick-start-master/edge-js-quick-start-master/src/ExternalLibrary/bin/Debug/netcoreapp2.0/ExternalLibrary.dll") ] });

@TheUnlocked
Copy link

I'm having this exact same issue.

@agracio
Copy link
Owner

agracio commented Mar 26, 2018

This appears to be OS specific. Works fine on Win 10 but fails on Win 7, likely fails on other Windows flavours as well. It will take me some time to resolve.

@TheUnlocked
Copy link

I'm using Windows 10.

@agracio
Copy link
Owner

agracio commented Mar 26, 2018

I cannot reproduce it on Win 10.

@agracio
Copy link
Owner

agracio commented Mar 27, 2018

There was an error in QuickStart.Core project reference caused by edge-js package update.
Please pull latest quick-start and rebuild .NET solution

@rktect
Copy link
Author

rktect commented Mar 27, 2018

Thanks for looking into this - it is very much appreciated!

I pulled the latest from github and re-compiled - and still get the same errors as above.

module.js:672 return process.dlopen(module, path._makeLong(filename)); ^ Error: Call to coreclr_create_delegate() for G failed with a return code of 0x80070002. at Object.Module._extensions..node (module.js:672:18) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at Object.<anonymous> (d:\dev\edge-js\edge-js-quick-start\node_modules\edge-js\lib\edge.js:53:8) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32)

With EDGE_APP_ROOT commented out:
d:\dev\edge-js\edge-js-quick-start\node_modules\edge-js\lib\edge.js:178 return edge.initializeClrFunc(options); ^ Error: Could not load file or assembly 'ExternalLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. at Object.exports.func (d:\dev\edge-js\edge-js-quick-start\node_modules\edge-js\lib\edge.js:178:17) at Object.<anonymous> (d:\dev\edge-js\edge-js-quick-start\main.js:30:22) at Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Function.Module.runMain (module.js:684:10) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3

I did manage to get my custom DLL reference working (I was missing adding the EdgeJs nuget package in my library). Things are working perfectly for me on Windows 10. Now I'm having issues getting the same code running on OSX and Linux (I need all 3 platforms) - I'm thinking this may be caused by the wrong version of nodejs or .net core installed. If I can't figure it out I'll open another issue. Any advice would be really helpful.

Thanks again and have a great day!

@agracio
Copy link
Owner

agracio commented Mar 27, 2018

You do not need Edge nuget package when you script from Node.js to CLR.
After you pulled latest for the repo and recompiled you should have EdgeJs.dll in your output directory, thats the only thing that was missing and causing problems.

@rktect
Copy link
Author

rktect commented Mar 27, 2018

This is strange - I do see the EdgeJs.dll in the specified path, but Visual Studio 2017 shows the yellow warning triangle on the assembly dependency reference.

DLL is correctly found in:
<HintPath>..\..\node_modules\edge-js\lib\bootstrap\bin\Release\netcoreapp1.1\EdgeJs.dll</HintPath>

I'll see what I can figure out on my end...

Re: adding nuget package - good to know. In my custom library I am scripting from CLR to Node.js, so I believe I do need the package in my library. Seems to work well now (on Windows).

@agracio
Copy link
Owner

agracio commented Mar 27, 2018

Take a look at readme for Edge.js, scripting Node.js from CLR only supported using .NET Framework.

@rktect
Copy link
Author

rktect commented Mar 27, 2018

I did read that. Does this include the CLR calling a nodejs callback passed in as an argument? Similar to this example: https://github.com/agracio/edge-js/blob/master/samples/211_events.js

Here is my javascript:

const start = edge.func({
    assemblyFile: baseDll,
    typeName: 'My.EdgeJsWrapper',
    methodName: 'Invoke',
    references: [
        (libDll)
    ]
});

var payload = {
    param1: 1234,
    myfunction: function (data, callback) {
        console.log('myfunction called ' + data);
        callback(null, 1);
    }
};

start(payload, function (error, result) {
    if (error) throw error;
    console.log(result);
});

And c#:

public async Task<object> Invoke(dynamic input)
{
    var myFunction = (Func<object, Task<object>>)input.myfunction;
    
    var result = (int)await myFunction("success");

    return $"successful CLR call {result}";
}

Is this a supported scenario? I had it working on OSX at one point - but I'm not able to get it running again now. I think I made a mistake upgrading my nodejs/npm versions and now I can't reverse it.

@rktect
Copy link
Author

rktect commented Mar 27, 2018

Also, in my case I am storing a reference to the nodejs callback 'myFunction', and calling it when certain events occur in the CLR.

@agracio
Copy link
Owner

agracio commented Mar 27, 2018

Scripting Node.js from CLR refers to C# code using Edge.js nuget package to access Edge functions, dont think it applies in your case, so you should not need a nuget package at all. https://github.com/agracio/edge-js#scripting-nodejs-from-clr.
I would suggest to pull fresh copy of edge-js-quick-start repo and try running it following the instructions, once you have it working then try adding your dlls. Make sure https://github.com/agracio/edge-js-quick-start/blob/master/main.js#L3 is correct for your build.

@rktect
Copy link
Author

rktect commented Mar 27, 2018

Fantastic! Thanks for all your help. I'll try what you suggested and see what I can get working.

@TheUnlocked
Copy link

TheUnlocked commented Mar 27, 2018

I still get the error upon require even in a newly downloaded edge-js-quick-start. If I comment out the EDGE_APP_ROOT line, the error goes away on require but it can't see the external library.

Edit: I tried it again and it's working in the quick start. Still doesn't work with my project though. Do I need to include Nodejs.dll in the build configs for my C# project?

@TheUnlocked
Copy link

Alright, I figured it out. For anyone else coming across this, in order to make your own dll work without building it with EdgeJS, run the quick start and copy the following files into your EDGE_APP_ROOT directory:

  1. EdgeJs.dll
  2. Microsoft.DotNet.InternalAbstractions.dll
  3. Newtonsoft.Json.dll
  4. Microsoft.Extensions.DependencyModel.dll

@agracio
Copy link
Owner

agracio commented Mar 28, 2018

EdgeJs.dll is part of the project and is added to output folder automatically. All of the dlls you listed are dependencies of QuickStart.Core.csproj project and also copied automatically.

Edit: I tried it again and it's working in the quick start. Still doesn't work with my project though. Do I need to include Nodejs.dll in the build configs for my C# project?

The purpose of quick start is to show how to configure your project so all the dlls are in place, take a look at QuickStart.Core.csproj and use the same reference structure in your project.

@radencode
Copy link

@agracio I am getting the same error Call to coreclr_create_delegate() for G failed with a return code of 0x80070002. however I only get it when I used electron-packager with asar set to true. If I set asar to false then the application runs just fine. I wonder if it just can't find the file because it's archived in the asar file?

@agracio
Copy link
Owner

agracio commented Jun 24, 2018

Edge.js cannot read paths from asar archive.
You should set all Edge.js assets as externals, and not include them as part of asar archive. You will have to add them as a separate item in your distribution.
Also take a look at this issue: agracio/electron-edge-js#21

@radencode
Copy link

radencode commented Jun 24, 2018 via email

@brianjenkins94
Copy link

I also see this issue out of the box on Windows 10 LTSC build 1809.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@rktect @brianjenkins94 @TheUnlocked @agracio @radencode and others