Coder Social home page Coder Social logo

agracio / electron-edge-js Goto Github PK

View Code? Open in Web Editor NEW
348.0 19.0 90.0 14.42 MB

Run .NET and Node.js code in-process on Windows, MacOS, and Linux

License: MIT License

Python 0.92% Batchfile 0.22% C# 8.17% JavaScript 5.18% C++ 85.04% C 0.39% HTML 0.09%

electron-edge-js's Introduction

.NET and Node.js in-process on Electron

This is a fork of edge-js adapted to support Electron

Windows binaries pre-compiled for

Electron Node.Js x86/x64 arm64
Electron 23.x v18.12.1 ✔️
Electron 24.x v18.14.0 ✔️
Electron 25.x v18.15.0 ✔️
Electron 26.x v18.16.1 ✔️
Electron 27.x v18.17.1 ✔️
Electron 28.x v18.18.2 ✔️
Electron 29.x v20.9.0 ✔️ ✔️
Electron 30.3.x v20.15.1 ✔️ ✔️
Electron 31.3.x v20.15.1 ✔️ ✔️
  • You do not need to use the same version of Node.js in your project as Electron Node.js version
  • On Linux and macOS npm install will compile binaries with correct Node.Js headers for a given Electron version.

Usage is the same as edge-js, replace require('edge-js') with require('electron-edge-js'):

npm install electron-edge-js
-var edge = require('edge-js');
+var edge = require('electron-edge-js');

var helloWorld = edge.func(function () {/*
    async (input) => {
        return ".NET Welcomes " + input.ToString();
    }
*/});

Why use electron-edge-js?

Electron is built using specific version of Node.js. To use edge-js in Electron project you would need to recompile it using the same Node.js version and Electron headers.

electron-edge-js comes precompiled with correct Node.js versions and headers.

Quick start

Sample app that shows how to work with .NET Core using inline code and compiled C# libraries.
https://github.com/agracio/electron-edge-js-quick-start

Packaging Electron application

electron-edge-js needs to be specified as an external module, some examples

webpack.config.js

externals: {
    'electron-edge-js': 'commonjs2 electron-edge-js',
},
node: {
    __dirname: false,
    __filename: false,
},

vue.config.js

module.export = {
    pluginOptions: {
        electronBuilder: {
            externals:["electron-edge-js"]
        }
    }
}

From #138

webpack.config.js

externals: {
    'electron-edge-js': 'commonjs2 electron-edge-js',
},
node: {
    __dirname: false,
    __filename: false,
},
extraResources:[
    "./node_modules/electron-edge-js/**",
]

Electron main.js

// https://github.com/ScottJMarshall/electron-webpack-module-resolution
require("module").globalPaths.push(process.cwd()+'/node_modules');
var edge = require('electron-edge-js');

Packaging example based on electron-edge-js-quick-start.
https://github.com/zenb/electron-edge-js-quick-start

Related issues to use for troubleshooting:
#39
#74
#21

Async execution

If electron-edge-js module is used on main Electron thread it will cause Electron app to freeze when executing long-running .NET code even if your C# code is fully async.
To avoid this you can use worker thread packages such as threads.js or piscina

This issue is not present when using Electron IPC

Workaround from #97

main.js

const { fork } = require("child_process"); fork("../child.js", [], { env: {file: 'filename'}, })

child.js

const path = require('path');
const powerpoint = require('office-script').powerpoint;
const filePath = '../../directory/';

powerpoint.open(path.join(${remotePath}${process.env.file}.pptx), function(err) {
    if(err) throw err;
});

Build

build.bat supports only Electron major versions.

Documentation

For full documentation see edge-js repo.

electron-edge-js's People

Contributors

accelazh avatar agracio avatar akozhemiakin avatar allisonshaw avatar ash47 avatar camhart avatar dependabot[bot] avatar ehellman avatar fuzatii avatar gdavidkov avatar georgiancamarasan avatar metesayan avatar peter-sabath avatar sa-matteohausner avatar tonino123 avatar trodi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

electron-edge-js's Issues

Cannot use it independently

It's your feature or bug?

I can use it well in electron, but something happend when I run node dotnet.js
Here is the report

return edge.initializeClrFunc(options);
               ^

TypeError: Cannot read property 'initializeClrFunc' of unde
fined
    at Object.exports.func (E:\github\ElectronWithDll-ATM\n
ode_modules\electron-edge-js\lib\edge.js:181:16)

source code is the demo from edgejs docs

const edge=require('electron-edge-js');

var hello = edge.func(function () {/*
 async (input) => {
 return "CSharp welcomes " + input.ToString();
 }
 */});

hello('Node.js', function (error, result) {
  if (error) throw error;
  console.log(result);
});

On windows7x64 phpstrom, nodejs v8.2.1

create winform from edge js will block electron ui

new winform from edge js will block electron ui , you can't click anywhere except close the form

sample code

var newForm = edge.func(
// eslint-disable-next-line no-unused-expressions

  #r "System.Windows.Forms.dll"
  using System.Windows.Forms;
  using System.Threading.Tasks;
  using System;
  public class Startup
  {
      public Task<object> Invoke(string command)
      {
        var tcs = new TaskCompletionSource<object>();
        var form = new Form();
        var button = new Button();
        var input = new TextBox();
        button.Text = "Hello World";
        button.Left = 100;
        button.Top = 100;
        input.Top = 100;
        form.Controls.Add(button);
        form.Controls.Add(input);
        button.Click += (x,y) => {
          var value = input.Text;
          form.Close();
          tcs.TrySetResult(value);
        };
        Application.Run(form);
        return tcs.Task;
      }
  }

`)

  newForm ('', function (error, result) {
    if (error) throw error
    console.log(result)
  })

`

Error when building Electron app for dist

When I package my electron app for distribution using electron-builder I am getting the following error:

Error: his is not a published, standalone application and we are unable to locate the .NET Core SDK.  Please make sure that it is installed; see http://microsoft.com/net/core for more details.

I am using the same .NET code as the quickstart for a proof-of-concept.

Any ideas on why I'd get this error? I have confirmed the .dlls are getting copied into the package.

8.3.6 Assembly resolution changes causing MEF composition failures in dynamically loaded assemblies.

8.3.6 Assembly resolution changes causing MEF composition failures in dynamically loaded assemblies.

We are creating a library using MEF (System.Composition) in .Net Core 2.1 for type resolution. It has the following project structure
Electron Edge JS loads QuickStart.Core
-> QuickStart.Core has a direct Reference to APISurface
-> APISurface uses LoadAssemblyFromContext to load APIImplementations and then MEF composition for DI

In the sample these are simple libraries but the real implementation is using nuget packages that add references directly to the QuickStart.Core library

This works in electron edge 8.3.5, but in 8.3.6 we get composition errors (see repro at https://github.com/nboon/MefLoadingIssueRepro/).

Message: "No export was found for the contract 'IMessageSender'.""IMessageSender"'."
Name: "System.Composition.Hosting.CompositionFailedException"
Source: "System.Composition.Runtime"
StackTrace: "
at System.Composition.CompositionContext.GetExport(CompositionContract contract)
at System.Composition.CompositionContext.GetExport[TExport](String contractName)
at MefLib.Resolved.SendMessage() in C:\GitHub\MefLoadingIssueRepro\src\MefLib\Resolved.cs:line 19
at QuickStart.Core.LocalMethods.UseMefLoadedAssembly(Object input) in C:\GitHub\MefLoadingIssueRepro\src\QuickStart.Core\LocalMethods.cs:line 48"
TargetSite:Object
message:"No export was found for the contract 'IMessageSender'.""IMessageSender"'."
name:"System.Composition.Hosting.CompositionFailedException"

Upon investigation it appears the issue is related to the assembly resolution optimizations added in 8.3.6. If we alter your assembly resolution logic to explicitly ignore the APISurface assembly, then composition succeeds.

Electron-Edge 6.5.5 High CPU Usage when calling winspool.Drv DocumentProperties extern method

Hi have logic where i am calling winspool.Drv DocumentProperties method to open the Printer properties dialog. I have a c# .net DLL from where winspool.Drv DocumentProperties extern method gets called and printer properties dialog opened successfully.

But after successive calling of that method , machines CPU usage gets high and remains high till i close my electron-edge application. i am having Windows 10 64 bit 16GB RAM.

When i am calling this method WMI Host provider application gets launched and start consuming memory. Also on some other machine Windows 10 64 bit 8 GB RAM ,System.Management Quota Violation exception get thrown after successive calls(5-6 times) to that method.

So some how memory leak is there , which i don't understand. Please help me to find out the solution.

Please check the below code snippet from my code.

in Node.js

  1. this.edge = electron.remote.require('electron-edge');
  2. handle = this.edge.func({ assemblyFile: assemblyPath });

handle.OpenPrintDialog(printerData, function (err, res) {
if (err)
deferred.reject(err);
else
deferred.resolve(res);
handle = null;
});

In C#

  1. InterOp pattern Startup class method called via electron-edge

public async Task Invoke(dynamic input)
{
IPrintController controller = GetPrintController(monitor);
return new
{
OpenPrintDialog = (Func<object, Task>)(
async (dynamic i) => await controller.OpenPrintDialog(Convert.ToString(i.PrinterName), Convert.ToString(i.PrintDialogSetup)))
}
}
5. middle layer to to convert passed printer settings and hand it over to main class

public async Task OpenPrintDialog(string printerName, string printDialogSetup)
{
return await PrintHelper.OpenPrintDialogAsync(printerName, printDialogSetup);
}

  1. Main class where all extern methods are declared and called

public class PrintHelper
{
[DllImport("kernel32.dll")]
static extern IntPtr GlobalLock(IntPtr hMem);

    [DllImport("kernel32.dll")]
    static extern bool GlobalUnlock(IntPtr hMem);

    [DllImport("kernel32.dll")]
    static extern bool GlobalFree(IntPtr hMem);

    [DllImport("winspool.Drv", EntryPoint = "DocumentPropertiesW", SetLastError = true, ExactSpelling  true, CallingConvention = CallingConvention.StdCall)]
    static extern int DocumentProperties(IntPtr hwnd, IntPtr hPrinter, [MarshalAs(UnmanagedType.LPWStr)] string pDeviceName, IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr GetForegroundWindow();

    private const int DM_PROMPT = 4;
    private const int DM_OUT_BUFFER = 2;
    private const int DM_IN_BUFFER = 8;
    private IntPtr ParentHandle;
    public DialogResult ShowDialog(PrinterSettings printerSettings)
    {

        ParentHandle = GetForegroundWindow();
        DialogResult dialogResult = DialogResult.Cancel;

        IntPtr devModeData = printerSettings.GetHdevmode();
        IntPtr iDevModeNew = GlobalLock(devModeData);
        long selectedOption = DocumentProperties(ParentHandle, IntPtr.Zero, printerSettings.PrinterName, iDevModeNew, iDevModeNew, DM_IN_BUFFER | DM_PROMPT | DM_OUT_BUFFER);

        if (selectedOption == (long)DialogResult.OK)
        {
            dialogResult = DialogResult.OK;
            printerSettings.SetHdevmode(devModeData);
            printerSettings.DefaultPageSettings.SetHdevmode(devModeData);
        }
        bool unlock = GlobalUnlock(iDevModeNew);
        unlock = GlobalUnlock(devModeData);

        GlobalFree(devModeData);
        GlobalFree(ParentHandle);
       return dialogResult;
    }

}

Uncaught Error with "edge_nativeclr.node"

image

Hi, I have an project and it works well with the 'electron-edge-js' 10.11.0.
We duplicated it to new project for upgrading and it uses 10.11.1.

but whatever I do, it shows this error.

How can i solve it?

Failed At System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)

I Want to use this to develop With BarTender SDK

While i run the Demo in VS 2015, It Works Well;
When i copy the Demo in electron-edge-js, it works bad

here is Demo

        using System.Threading.Tasks;
        using Seagull.BarTender.Print;
    
        public class Startup
        {
            public async Task<object> Invoke(object input)
            {
                using (Engine btEngine = new Engine())

                {

                    // Application specific code 

                    // Explicitly start the engine 

                    btEngine.Start();

                    LabelFormatDocument format = btEngine.Documents.Open(@"C:\Users\Administrator\Desktop\BartenderTemplate\test.btw");
                    format.PrintSetup.IdenticalCopiesOfLabel = 1;
                    //format.PrintSetup.PrinterName = "TOSHIBA B-EX4T1 (203 dpi)";
                    format.PrintSetup.PrinterName = "Microsoft Print to PDF";
                    format.Print();

                // Application-specific code 

                // Assuming the application wants to save changes, 

                //it can be easily done at Stop time. 

                btEngine.Stop(SaveOptions.SaveChanges);
                    return 0;
                }
                return 0;
            }
        }

And Error at Here

message:"路径中具有非法字符。"
name:"System.ArgumentException"
StackTrace:

"   At System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
   At System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
   At System.IO.FileInfo.Init(String fileName, Boolean checkHost)
   At System.ComponentModel.Design.RuntimeLicenseContext.GetSavedLicenseKey(Type type, Assembly resourceAssembly)
   At System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo(Int32& fDesignTime, IntPtr& bstrKey, RuntimeTypeHandle rth)
   At  Seagull.BarTender.Print.Engine.Start(EngineSettings engineSettings, LicenseKeyManaged license, IntPtr interactiveUserHandle)"

I know less about C#, but it seems that PermissionChecks Failed, I tried

  • change electron.exe electron.exe.manifest and repackaged by mt.exe
  • run electron.exe by Admin Permisson Always use right click
    Unfortunately, all of them doesn't work;

Very Confused, need Help;

here is my package.json

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^3.0.7"
  },
  "dependencies": {
    "electron-edge-js": "^10.11.0"
  }
}

here is my OS
image

And node

C:\Users\Administrator>node -v
v10.2.0

Electron process gets aborted when using native clr version for Electron >=4.0

This is no bug of electron-edge-js, but a big trap someone using it can run into.

When building the native CLR version in debug using Electron >= 4.0 what requires the use of the delayed load hook, there is a problem with node-gyp. They provide the file win_delay_load_hook.cc which is used for DLL redirection.

Unfortunately even the current latest version 5.0.3 is lacking an already commited fix 5736079

Without it you might end up with an abort message from the windows loader, because the loader code gets enriched to initialize the framework which is a bad idea when executing this DLL-loader code.

Took me hours to sort out.

Error loading electron (electron ^5.0.8 and electron-edge-js ^12.0.1)

Hi
I'm unable to start my app next updating electron ^5.0.8 and electron-edge-js ^12.0.1
The same project with electron 4.x works perfectly (and always electron-edge-js ^12.0.1)

npm ERR! code ELIFECYCLE
npm ERR! errno 3221226505
npm ERR! [email protected] start: 'electron .'
npm ERR! Exit status 3221226505
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

(I watched the issue #32 but I red that was solved in 10.11.1)

Any suggestions?

Thanks,
Andrea

App cannot be built in docker image 'electronuserland/builder:wine'

I'm trying to build my electron app using the well-known docker image.

The following error occurs when the dependencies are installed:

> [email protected] install /builds/project-0/Client/node_modules/edge-cs
> node tools/install.js


> [email protected] install /builds/project-0/Client/node_modules/electron-edge
> node tools/install.js

make: Entering directory '/builds/project-0/Client/node_modules/electron-edge/build'
  CXX(target) Release/obj.target/edge_nativeclr/src/mono/clractioncontext.o
  CXX(target) Release/obj.target/edge_nativeclr/src/mono/clrfunc.o
../src/mono/clrfunc.cpp: In static member function ‘static v8::Local ClrFunc::Initialize(MonoObject*)’:
../src/mono/clrfunc.cpp:55:102: warning: ‘static v8::Local v8::Script::Compile(v8::Local, v8::ScriptOrigin*)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
         v8::Local codeFunction = v8::Local::Cast(v8::Script::Compile(code)->Run());
           ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:1235:38: note: declared here
                        Local<Script> Compile(Local source,
                                      ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
../src/mono/clrfunc.cpp:55:109: warning: ‘v8::Local v8::Script::Run()’ is deprecated: Use maybe version [-Wdeprecated-declarations]
         v8::Local codeFunction = v8::Local::Cast(v8::Script::Compile(code)->Run());
                  ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:1250:51: note: declared here
   V8_DEPRECATED("Use maybe version", Local Run());
                                                   ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
../src/mono/clrfunc.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE ClrFunc::Initialize(Nan::NAN_METHOD_ARGS_TYPE)’:
../src/mono/clrfunc.cpp:80:54: warning: ‘v8::String::Utf8Value::Utf8Value(v8::Local)’ is deprecated: Use Isolate version [-Wdeprecated-declarations]
         String::Utf8Value assemblyFile(jsassemblyFile);
                                                      ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:2822:28: note: declared here
                   explicit Utf8Value(Local obj));
                            ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
../src/mono/clrfunc.cpp:81:105: warning: ‘v8::String::Utf8Value::Utf8Value(v8::Local)’ is deprecated: Use Isolate version [-Wdeprecated-declarations]
         String::Utf8Value nativeTypeName(options->Get(Nan::New("typeName").ToLocalChecked()));
              ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:2822:28: note: declared here
                   explicit Utf8Value(Local obj));
                            ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
../src/mono/clrfunc.cpp:82:109: warning: ‘v8::String::Utf8Value::Utf8Value(v8::Local)’ is deprecated: Use Isolate version [-Wdeprecated-declarations]
         String::Utf8Value nativeMethodName(options->Get(Nan::New("methodName").ToLocalChecked()));
                  ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:2822:28: note: declared here
                   explicit Utf8Value(Local obj));
                            ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
../src/mono/clrfunc.cpp:95:103: warning: ‘v8::String::Utf8Value::Utf8Value(v8::Local)’ is deprecated: Use Isolate version [-Wdeprecated-declarations]
         String::Utf8Value compilerFile(options->Get(Nan::New("compiler").ToLocalChecked()));
            ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:2822:28: note: declared here
                   explicit Utf8Value(Local obj));
                            ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
../src/mono/clrfunc.cpp: In static member function ‘static v8::Local ClrFunc::MarshalCLRExceptionToV8(MonoException*)’:
../src/mono/clrfunc.cpp:365:55: error: no matching function for call to ‘v8::Object::SetPrototype(v8::Local)’
     result->SetPrototype(v8::Exception::Error(message));
                                                       ^
In file included from ../src/mono/../common/edge_common.h:4:0,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:3308:37: note: candidate: v8::Maybe v8::Object::SetPrototype(v8::Local, v8::Local)
   V8_WARN_UNUSED_RESULT Maybe SetPrototype(Local context,
                                     ^
/root/.node-gyp/10.1.0/include/node/v8.h:3308:37: note:   candidate expects 2 arguments, 1provided
../src/mono/clrfunc.cpp: In static member function ‘static MonoObject* ClrFunc::MarshalV8ToCLR(v8::Local)’:
../src/mono/clrfunc.cpp:493:48: warning: ‘v8::String::Utf8Value::Utf8Value(v8::Local)’ is deprecated: Use Isolate version [-Wdeprecated-declarations]
             v8::String::Utf8Value utf8name(name);
                                                ^
In file included from /root/.node-gyp/10.1.0/include/node/v8.h:26:0,
                 from ../src/mono/../common/edge_common.h:4,
                 from ../src/mono/edge.h:4,
                 from ../src/mono/clrfunc.cpp:1:
/root/.node-gyp/10.1.0/include/node/v8.h:2822:28: note: declared here
                   explicit Utf8Value(Local obj));
                            ^
/root/.node-gyp/10.1.0/include/node/v8config.h:318:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^
edge_nativeclr.target.mk:110: recipe for target 'Release/obj.target/edge_nativeclr/src/mono/clrfunc.o' failed
make: Leaving directory '/builds/project-0/Client/node_modules/electron-edge/build'
make: *** [Release/obj.target/edge_nativeclr/src/mono/clrfunc.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:235:12)
gyp ERR! System Linux 4.9.87-linuxkit-aufs
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /builds/project-0/Client/node_modules/electron-edge
gyp ERR! node -v v10.1.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok

Does anybody know what's wrong here?

Cannot find module

Environments:

"electron-edge-js": "^12.0.1",
"electron": "^5.0.6",
"vue-cli-plugin-electron-builder": "^1.3.4",

Running:, vue-cli
Runtime: Node v10.16.1
Operating System: windows 64bit

Steps to reproduce:

node_modules/elcetron-edge-js/lib/edge.js
add console.log
20190804_204753

vue-cli-service electron:serve --mode development
20190804_204244

next step
vue.config.js add configuration
20190804_204333

vue-cli-service electron:serve --mode development
20190804_204023

repo: https://github.com/aispark/vuecli-electron-test

Can't load Core2 dll

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>

namespace Hello.Core
{
    public class Startup
    {
        public async Task<object> Invoke(object input)
        {
            return "Hello from dot net core 2";
        }
    }
}

The project is located Here with my entry point

I am using the electron-quick-start project and added the following lines of code to main.js

  var helloWorld = edge.func({
    assemblyFile: path.join(__dirname, '\\MEF\\Hello.Core\\bin\\Debug\\netcoreapp2.0\\Hello.Core.dll'),
    typeName: 'Hello.Core.Startup'
  });

Trying to load "Hello.Core.dll" results in the following error;

net core electron edge js cant load

The electron version is;

Hello World!

We are using Node.js 7.9.0, Chromium 58.0.3029.110, and Electron 1.7.9.

I was hoping this would support .Net Core 2.

TypeError: edge.initializeClrFunc is not a function (electron 2, 3)

Hello, noble coders!

On my machine everything works like a charm, in development and even on production builds that i made with electron-packager and electron-builder. On my machine apps works fine on windows and macOS. But when i tried install or launch app from directory on different PC/Mac or clean virtual machine i got absolutely annoying edge error:

polyfills.4f1f9ade919f8c9100b8.js:1 ERROR Error: Uncaught (in promise): TypeError: edge.initializeClrFunc is not a function
TypeError: edge.initializeClrFunc is not a function
at Object.exports.func (C:\b\resources\app\node_modules\electron-edge-js\lib\edge.js:185:17)
at new t (file:///C:/b/resources/app/dist/main.cd46168f267b484bf4ac.js:1:375289)

App uses dotnet core 2.2 with published win7-x64 runtime, electron 3 and latest electron-edge-js.
Few days i spend beating this error and i was defeated.

Initial app testing setup was clean Win 7 SP1 x64 on Virtual Box, but further i tried:

  • enable/disable asar packing
  • install latest updates (on test OS)
  • install nodejs and dotnet core 2.2 (on test OS)
  • install visual studio with all c++ build libraries (on test OS)
  • install different versions of microsoft c++ redistributable from 2010 til 2017, both x86 and x64 (on test OS).
  • build edge_coreclr.node with --debug
  • run dependency walker on my .exe
    got those general dll load errors%

API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
BLUETOOTHAPIS.DLL
DCOMP.DLL
IESHIMS.DLL
virtualbox_win764_22_01_2019_12_58_19

but every time i got same error.
Setting process.env.EDGE_DEBUG = 1 didn't help, because error is thrown before initialization of edge.js.

Appreciate any help or clues =)
P.S. @agracio thank you for your work, this library is the best electron-c# bridge i ever tried!

Packaging for Windows from Mac or Linux

Hey Agracio,

My app is targeting different platforms, including Windows, Linux and macOS (both ia32 and x64) and modern Node versions. The app doesn't have any platform-specific behavior.

If I install the project's dependencies using npm install, electron-edge-js downloads binaries just for the current platform (let's say win32, x64, Node v8.1).

Could you maybe make your package node-pre-gyp ready? So I can create packages from any platform for any platform?

Yours Sincerely,

Dion David

Support for electron 6?

First of all thanks for a wonderful library. Electron 6 has been released few days ago. Just wondering are there any plans to add support for Electron 6 to this library. Asking because the previous released library version does not work well with Electron 5 as mentioned in issue #47.

I am willing to help doing this task, but will need some pointers. Thanks!

xlocale.h not found on Ubuntu while installing

I'm having trouble installing this awesome module on Ubuntu 17.10:

vadi@volga:~/Programs/packager-demo$ rm -rf node_modules/electron-edge-js/
vadi@volga:~/Programs/packager-demo$ npm install

> [email protected] install /home/vadi/Programs/packager-demo/node_modules/electron-edge-js
> node tools/install.js

make: Entering directory '/home/vadi/Programs/packager-demo/node_modules/electron-edge-js/build'
  TOUCH Release/obj.target/edge_nativeclr.stamp
  CXX(target) Release/obj.target/edge_coreclr/src/common/v8synchronizationcontext.o
  CXX(target) Release/obj.target/edge_coreclr/src/common/callbackhelper.o
  CXX(target) Release/obj.target/edge_coreclr/src/common/edge.o
  CXX(target) Release/obj.target/edge_coreclr/src/CoreCLREmbedding/coreclrembedding.o
In file included from ../src/CoreCLREmbedding/json/casablanca/include/cpprest/json.h:37:0,
                 from ../src/CoreCLREmbedding/coreclrembedding.cpp:8:
../src/CoreCLREmbedding/json/casablanca/include/cpprest/asyncrt_utils.h:44:10: fatal error: xlocale.h: No such file or directory
 #include <xlocale.h>
          ^~~~~~~~~~~
compilation terminated.
edge_coreclr.target.mk:120: recipe for target 'Release/obj.target/edge_coreclr/src/CoreCLREmbedding/coreclrembedding.o' failed
make: *** [Release/obj.target/edge_coreclr/src/CoreCLREmbedding/coreclrembedding.o] Error 1

I'm not sure which xlocale.h is it looking for? I already installed the dependencies necessary for the build (sans mono):

curl g++ pkg-config libgdiplus libunwind8 libssl-dev make gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev unzip

electron5.0.3 error Uncaught TypeError: edge.initializeClrFunc is not a function

envirenment: nodejs 12.0.0 (x86) , electron 4.0.4 , electron-edge-js 12.0.1
the demo is ok, but when i update electron to 5.0.3 and delete node_modules folder then run npm i
command, the demo is failed
, it output error "Uncaught TypeError: edge.initializeClrFunc is not a function", the main code is [
process.env.EDGE_USE_CORECLR = 1;
var edge = require("electron-edge-js");

var helloWorld = edge.func(function() {
/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/
});

helloWorld("JavaScript", function(error, result) {
if (error) throw error;
alert("hello");
});]
when i use nodejs 12.0.0(x64) the demo is ok. I run "build.bat release 12.0.0" command in electron-edge-js folder rebuild is success, but the error is save
demo is https://github.com/agracio/electron-edge-js-quick-start

Does anyone have any Suggestions

Marshaling Problem with properties in structs

When there are structs (or classes which use them) and these structs use properties, the resulting object on the javascript side is corrupted. (fields work fine!)
Values from those properties are mostly 0 but sometimes contain some "random" value.
I never encountered a crash here from a possibly bad pointer.

This problem is only present with the mono implementation (on Mac, mono 5.4)

Using the following C# file

using System;
using System.Threading.Tasks;

namespace Test
{
	public struct Data
	{
		public int Value1;
		public int Value2;
		public int Value3 { get; set; }
		public int Value4 { get; set; }

		public Data(int aMult)
		{
		  Value1 = 1* aMult;
		  Value2 = 2* aMult;
		  Value3 = 3* aMult;
		  Value4 = 4* aMult;
		}
	}

	public class EdgeTest
	{
		public async Task<object> GetData(dynamic aInput)
		{
			return new Data(1);
		}
	}
}

with the (stripped) javascript code

const edge = require('electron-edge-js');

var clrMethod = edge.func({
    assemblyFile: 'EdgeTest.dll',
    typeName: 'Test.EdgeTest',
    methodName: 'GetData' // This must be Func<object,Task<object>>
});	

clrMethod(null, function (error, result) {
    if (error) throw error
    console.log(JSON.stringify(result))
});

outputs {"Value1":1,"Value2":2,"Value3":0,"Value4":0}

Hello World is not working with electron 5 / node 12

I have created a basic hello word example. It does not use any external dll. Just a basic inline .net statement. But if you do "npm start" it fails without any proper error message.

https://github.com/ReOrg360/test-electron-edge-js

Looks like it fails as we are NOT using EDGE_USE_CORECLR by using below line of code. While I think it should still work fine without EDGE_USE_CORECLR.

process.env.EDGE_USE_CORECLR = 1;

Please help. I am willing to help to fix it but need some pointers. :)

Example and d.ts issues with typescript?

Just doing a quick spike using this and I noticed right away that the example on the front page implies that the func method should only take a single param (the method body) but the d.ts implies that you need to pass in func("cs", methodBody).

However once you do this typescript (latest 2.8.3) you get an error:

A parameter initializer is only allowed in a function or constructor implementation.

Am I doing anything crazy here?

import * as edge from "electron-edge-js";

showOutput(){
            const helloWorld = edge.func("cs", `async (input) => {
                    return ".NET Welcomes " + input.ToString();
                }`);

            helloWorld("test", function (error, result) {
                if (error) throw error;
                console.log(result);
            });
        }

ELectron-Edge-Js and .net standard 2.0 compatibility issue

Hi,

I have created a sample electron app and installed electron-edge-js package. Tried to add a .net framework class library dll and called a method from it. It worked fine.

But the issue is, I tried to create a .net standard 2.0 class library and referenced that dll in my app and tried calling a method from that (a method which simply returns a string). But I got the error " 'Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'"

Please help me out to find a solution since the project is critical.

Thanks in advance

Using electron-edge-js with self-contained DLLs

Hi there,

I was able to successfully run the demo you made for .NET Core 2.0 interop. However, this has risen a question towards how to use self-contained .NET Core 2.0 DLLs. We really need to have a standalone, self-contained electron application and relying on .NET Core to be installed is not an option.

I can see some folders in the source tree related to this, so I tried to publish the DLL in the sample as self-contained, however it still used the shared .NET Core host.

Do you have any experience with this?

Many thanks,

Jan

Can we force load .NET 4.7.2? ...Net 4.5.2 has security issue where TLS 1.0 is used

We've noticed that our Electron app appears to be loading .NET 4.5.2 which is causing our HTTP connections to use TLS 1.0.

Our understanding from experimentation and reading this article:

https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls

... is that .Net 4.7.2 and newer "do the right thing", meaning the connections are established using the newest protocol supported by the server, in our case, TLS 1.2 or 1.3

We are using Electron v 1.7.9 with Node 8.16.
electron-edge-js version is 12.0.1

Is there some sort of configuration that would allow us to force using .NET 4.7.2?

Or, more specifically, is there any way to ensure HTTP connections use TLS 1.2 or newer?

Thanks very much! Any guidance is appreciated.

Inline C# script comment removed

This may be more a question about what version of typescript to use. I was attempting to implement a spike almost identical to an example in the original edge project, but using electron-edge-js, as a Visual Studio Code extension, and referencing an externally compiled C# that was essentially the Person class in the example. However, I am getting an error, "If .NET source is provided as JavaScript function, function body must be a /* ... */ comment."

So I took my code and validated that it matched the regex in the edge.js if statement. It did. So I stepped into the debugger, and the value passed in as the first parameter, initially "language" (as options was not passed in, just the function), and the function had curly braces with a newline in between, but no comment with the C# script in it.

language.toString(): "function () {\r\n    }"

So I hunted around and found a Typescript bug that strips comments like the ones required by edge, even when removeComments is set to false.

Am I doing something wrong? I had to reinstall tsc and it installed the latest, 2.9.2. Do I need to use a different version? Is there a flag I am missing? Could another tool in Visual Studio Code be stripping comments before the extension.ts is compiled? The commented script is displayed in the debugger. Thank you for any assistance.

Not able to use a .net dll which has a reference to an x86 dll

it throws error App thew an error during load Error: Could not load file or assembly xxx.dll or one of its dependencied. An attempt was made to load a program with an incorrect format I have windows 7 64 bit and I have a x86 c# library project I am able to call a x86 dll which has no other reference, but if I add reference dll it fails
I am using .net framework 4.5

undefined returned from call using result from edge.func()

My code is essentially the HelloWord example embedded in the extension.ts of a Visual Studio Code extension. My dev environment is Visual Studio Code, but I have Visual Studio Enterprise 2017 with almost all the optional modules installed.

From extension.ts:

   var createHelloState = edge.func({
        source: path.join(__dirname, "..\\Startup.csx"),
        references: [path.join(__dirname, "..\\dlls\\TestState.dll")],
    });

    var helloState = createHelloState(__dirname);

Startup.csx:

            using System;
            using System.Threading.Tasks;
            using TestState;
            
            public class Startup
            {
                public async Task<object> Invoke(string appDir)
                {
                    var helloState = new HelloState(appDir);
                    return new {
                        getName = (Func<object,Task<object>>)(
                            async (i) => 
                            { 
                                return helloState.GetName(); 
                            }
                        ),
                        setName = (Func<object,Task<object>>)(
                            async (newName) => 
                            { 
                                helloState.SetName((string)newName); 
                                return helloState.GetName();
                            }
                        )
                    };
                }
            }

After executing the edge.func() call, createHelloState has a value of "function (d, cb) { … }". However, calling createHelloState returns an undefined. electron-edge-js is version 8.3.6. node-gyp is version 3.7.0. node is v8.11.3. npm is version 5.6.0. Is there a way to debug into the C# from the typescript call? Is there anything obvious that I am doing wrong? Can you have silent failures in the code generated proxies between typescript and C# that would result in not returning the tuple of Func<> objects? How do you debug this?

EDGE_USE_CORECLR doesn't work properly

builtEdge = path.resolve(__dirname, '../build/Release/' + (process.env.EDGE_USE_CORECLR || !fs.existsSync(path.resolve(__dirname, '../build/Release/edge_nativeclr.node')) ? 'edge_coreclr.node' : 'edge_nativeclr.node'));

This comparison is failing for some reason, here's the debug i did

var check1 = ((process.env.EDGE_USE_CORECLR || !fs.existsSync(path.resolve(__dirname, '../build/Release/edge_nativeclr.node'))) ? 'edge_coreclr.node' : 'edge_nativeclr.node');
var check2 = !fs.existsSync(path.resolve(__dirname, '../build/Release/edge_nativeclr.node'));
var check3 = !fs.existsSync(path.resolve(__dirname, '../build/Release/edge_nativeclr.node')) ? 'edge_coreclr.node' : 'edge_nativeclr.node';
console.log(
    path.resolve(__dirname, '../build/Release/edge_nativeclr.node'), //<fullPath>\build\Release\edge_nativeclr.node
    process.env.EDGE_USE_CORECLR, //false
    check1, //edge_coreclr.node <-- problem
    check2, //false
    check3 //edge_nativeclr.node
);

I'm trying to use .NET on Windows but CoreCLR gets used every time due to the failing check

Install on MacOS Failing with Unable to find package Microsoft.CodeAnalysis.CSharp.Workspaces

I am attempting to do the npm install electron-edge-js, and getting this output:

... clipped upper messages for brevity

Restoring packages for /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj...
Restoring packages for /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj...
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: Unable to find package Microsoft.CodeAnalysis.CSharp.Workspaces with version (= 2.8.0)
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: - Found 53 version(s) in nuget.org [ Nearest version: 2.8.0-beta4 ]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: - Found 2 version(s) in /usr/local/share/dotnet/sdk/NuGetFallbackFolder [ Nearest version: 2.6.1 ]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: - Found 0 version(s) in LSI
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: Unable to find package Microsoft.CodeAnalysis.VisualBasic.Workspaces with version (= 2.8.0)
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: - Found 52 version(s) in nuget.org [ Nearest version: 2.8.0-beta4 ]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: - Found 0 version(s) in LSI
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj : error NU1102: - Found 0 version(s) in /usr/local/share/dotnet/sdk/NuGetFallbackFolder
Generating MSBuild file /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/obj/bootstrap.csproj.nuget.g.props.
Generating MSBuild file /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/obj/bootstrap.csproj.nuget.g.targets.
Restore failed in 1.24 sec for /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj.
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: Unable to find package Microsoft.CodeAnalysis.CSharp.Workspaces with version (= 2.8.0) [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: - Found 53 version(s) in nuget.org [ Nearest version: 2.8.0-beta4 ] [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: - Found 2 version(s) in /usr/local/share/dotnet/sdk/NuGetFallbackFolder [ Nearest version: 2.6.1 ] [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: - Found 0 version(s) in LSI [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: Unable to find package Microsoft.CodeAnalysis.VisualBasic.Workspaces with version (= 2.8.0) [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: - Found 52 version(s) in nuget.org [ Nearest version: 2.8.0-beta4 ] [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: - Found 0 version(s) in LSI [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj : error NU1102: - Found 0 version(s) in /usr/local/share/dotnet/sdk/NuGetFallbackFolder [/Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/lib/bootstrap/bootstrap.csproj]
Generating MSBuild file /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/obj/Edge.js.csproj.nuget.g.props.
Generating MSBuild file /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/obj/Edge.js.csproj.nuget.g.targets.
Restore failed in 1.38 sec for /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js/src/double/Edge.js/Edge.js.csproj.
make: *** [lib/bootstrap/project.lock.json] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:194:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 18.0.0
gyp ERR! command "/usr/local/Cellar/node/7.9.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build" "--target=2.0.5" "--disturl=https://atom.io/download/atom-shell"
gyp ERR! cwd /Users/dlitty/src/lsi/git/web/app/commoncore/utilities/ConnectionsEditor/node_modules/electron-edge-js
gyp ERR! node -v v7.9.0
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok

Any ideas on what is causing this?

Lags + How to use unsafe build with csx

Hello,
I have two questions that I hope you have the answer:

Lags

JS

edge.func('nfc.csx')(command, (error, result) => {});

C#

public async Task<object> Invoke(int command)
{
    await Task.Run(() => {
        ...
    }
    ...
}

The main thread of the app freeze when I execute this. I reduce a litle the freeze time using Task.Run but it's realy tricky with a .net function that need to be called every 500ms.

New informations

If I put the csx code in js using /* */, there is no freeze anymore

Unsafe

When I try to put unsafe block in csx, it ask me to add /unsafe on compiler.

[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderSerialNumber")]
public unsafe static extern DL_STATUS GetReaderSerialNumber(ulong* serial_number);

I need unsafe because the library was made like this.
I tried to put a project.json on the main path of my project but nothing changed.

{
    "buildOptions": {
        "allowUnsafe": true
    }
}

Thanks in advance for your help.

.NET support for the library

Hi
We are looking to work in .NET 4.6.1. I have noticed that the original project only mentions 4.5. Does this library support dlls made with .NET 4.6.1?
Thanks

1.8.x build

Is it supposed to be working with Electron 1.8.x? I can install it with 1.7.x without problems, but 1.8.x will give me this:

Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1

does not work within electron-forge (or at all?)

I've tried on nearly every option in the support matrix:

Electron 1.4.x - Node.js v6.5.0.
Electron 1.6.x - Node.js v7.4.0.
Electron 1.7.x - Node.js v7.9.0.
Electron 1.8.x - Node.js v8.2.1.
Electron 2.0.x - Node.js v8.9.3.
Electron 3.0.x - Node.js v10.2.0.

None of these have worked. The log is rather long, so I'll attach it to this post.

You can see my package.json here (the electron branch is where I've been working on this).

Weirdly, it works on OSX, but it refuses to work at all on windows.

electron5.0.3 ia32 error Uncaught TypeError: edge.initializeClrFunc is not a function

Hi,
I have a problem,
development environment: nodejs 12.8.0 (x64) , electron 5.0.3(x64) , electron-edge-js 12.0.1
the demo is ok, but when i update electron to 5.0.3(x86) and rebuild .net dll to x86 then delete node_modules folder then run npm i
command, the demo is failed, it output error "Uncaught TypeError: edge.initializeClrFunc is not a function", the main code is [
process.env.EDGE_USE_CORECLR = 1;
var edge = require("electron-edge-js");

var helloWorld = edge.func(function() {
/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/
});

helloWorld("JavaScript", function(error, result) {
if (error) throw error;
alert("hello");
});]
demo is https://github.com/agracio/electron-edge-js-quick-start

[1] error Command failed with exit code 3221226505.

Hey, I just installed electron-edge-js for the first time and put this at the top of my electron app to see if it works:


var helloWorld = edge.func(function () {/*
    async (input) => {
        return ".NET Welcomes " + input.ToString();
    }
*/});

now when I start electron it just says:

[1] error Command failed with exit code 3221226505.

I'm using :
Electron v5 and Windows 10

"App threw an error during load" with latest electron 4.0.0 and electron-edge-js 10.11.0

Hey there,

upgraded to electron 3.0.13 and electron-edge-js 10.11.0 lately and everything was running fine (app could be build, started and .Net integration was working).

After the stable release of electron 4.0.0 I now tried to upgrade it but my electron app fails on start with the following error:

 App threw an error during load
Error: The specified procedure could not be found.
\\?\C:\Users\...\dist\node_modules\electron-edge-js\lib\native\win32\x64\10.11.0\edge_nativeclr.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:722:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
    at Module.load (internal/modules/cjs/loader.js:602:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:541:12)
    at Function.Module._load (internal/modules/cjs/loader.js:533:3)
    at Module.require (internal/modules/cjs/loader.js:640:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\...\dist\node_modules\electron-edge-js\lib\edge.js:59:10)
    at Object.<anonymous> (C:\Users\...\dist\node_modules\electron-edge-js\lib\edge.js:188:3)
error: Uncaught exception:  Error: The specified procedure could not be found.
\\?\C:\Users\...\dist\node_modules\electron-edge-js\lib\native\win32\x64\10.11.0\edge_nativeclr.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:722:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
    at Module.load (internal/modules/cjs/loader.js:602:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:541:12)
    at Function.Module._load (internal/modules/cjs/loader.js:533:3)
    at Module.require (internal/modules/cjs/loader.js:640:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\...\dist\node_modules\electron-edge-js\lib\edge.js:59:10)
    at Object.<anonymous> (C:\Users\...\dist\node_modules\electron-edge-js\lib\edge.js:188:3)

I already tried a clean install by removing the node_module folders.

Here on github it looks like electron-edge-js should already be ready for electron 4.x.x releases but seems its not or do I miss something in my setup?

best regards
Max

DevTools empty (electron 5.0.9, node 10.16)

This is probably a dumb question but I am new to C# and I just can't get the example to work. I used the electron quick start project ( not the one from this electron-edge, the electron default one).

I added nodeIntegration to it, the added the following code to renderer.js

`var edge = require('electron-edge-js');

var helloWorld = edge.func(function () {/*
async (input) => {
return ".NET Welcomes " + input.ToString();
}
*/});

helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});
`

Nothing else was added. It seems like when I start the program with npm start though, the DevTools console immediately gets disconnected and the App remains blank

Any idea why this doesn't work at all? I feel like I am missing something easy

Why I use callback method to call C# functions still freezes UI?

var TurnPasswordOn = edgejs.func({
    assemblyFile: XXX.dll',
    typeName: 'ABCDEFG',
    methodName: "TurnPasswordOn"
});

TurnPasswordOn(TurnPasswordOnInfo, function(err, ret){
                    if(err)
                    {
                        throw err;
                    }
                    if(ret == true)
                    {
                        alert("Set password success");
                    }
                    else
                    {
                        alert("Set password fail");
                    }
 });

Because the TurnPasswordOn function needs to take about 30~40 seconds, I want to do a loader animation.

But when the code executes to TurnPasswordOn function, it freezes the UI.
The loader animation is frozen (not going).
I'm just curious why I use callback function, but it still freezes the UI?

Thanks for helping.

dotnet core assemblies not found when running through edge

Hello,

I'm not sure I understand what the issue is, so I'm sorry if this issue is confusing, but I can clarify any questions you have.

The error I'm getting is this:

System.InvalidOperationException: There was an error reflecting type 'InvoiceSchema.SupplierConnectInvoice'.
---> System.TypeLoadException: Could not load type 'System.Xml.Serialization.XmlRootAttribute' 
from assembly 'System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

My C# entry point looks like this:

namespace MyNamespace
{
    public class Startup
    {
        public async Task<object> Invoke(dynamic input)
        {
            Console.WriteLine(input.file);
            await Task.CompletedTask;
            try
            {
                var exists = File.Exists(input.file);
                Console.WriteLine("File exists: " + exists);
                if (!exists) return "Invalid file path";
                List<SupplierConnectInvoice> invoices = Invoices.Read(input.file);
                Console.WriteLine(invoices);
                return new { invoices = invoices };
            }
            catch (Exception e)
            {
                Debugger.Break();
                Exception exception = e;
                Console.WriteLine(e.Data);
                Console.WriteLine(e.HelpLink);
                Console.WriteLine(e.HResult);
                Console.WriteLine(e.InnerException);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
            return null;
        }
    }
}

The Invoices class looks like this (just using XML serialization/deserialization):

namespace MyNamespace
{
    public static class Invoices
    {
        public static void Write(string path, List<SupplierConnectInvoice> invoices)
        {
            var xml = new XmlSerializer(typeof(List<SupplierConnectInvoice>));
            File.Delete(path);
            using (var writer = new StreamWriter(path))
            {
                xml.Serialize(writer, invoices);
            }
        }

        public static List<SupplierConnectInvoice> Read(string path)
        {
            var invoices = new List<SupplierConnectInvoice>();
            var xml = new XmlSerializer(typeof(List<SupplierConnectInvoice>));
            using (Stream reader = new FileStream(path, FileMode.Open))
            {
                invoices = (List<SupplierConnectInvoice>)xml.Deserialize(reader);
            }
            return invoices;
        }
    }
}

But if I just run this entry point straight from C# like this, I don't get any errors:

namespace MyNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = new Startup().Invoke(new { file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "invoices.xml" }).Result;
        }
    }
}

Before I began investigating the issue, my .csproj file looked like this:

<Project Sdk="Microsoft.NET.Sdk">

  <ItemGroup>
    <PackageReference Include="Microsoft.XmlSerializer.Generator" Version="2.0.0" />
    <PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
    <PackageReference Include="System.Runtime.Serialization.Xml" Version="4.3.0" />
    <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.XmlSerializer.Generator" Version="2.0.0" />
  </ItemGroup>

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

</Project>

After reading a bunch on github about issues that sounded similar, it now looks like:

<Project Sdk="Microsoft.NET.Sdk">

  <ItemGroup>
    <PackageReference Include="Edge.js" Version="8.2.1" />
    <PackageReference Include="Microsoft.XmlSerializer.Generator" Version="2.0.0" />
    <PackageReference Include="NETStandard.Library" Version="2.0.3" />
    <PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
    <PackageReference Include="System.Runtime.Serialization.Xml" Version="4.3.0" />
    <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
    <PackageReference Include="System.Xml.ReaderWriter" Version="4.3.1">
      <Private>True</Private>
    </PackageReference>
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.XmlSerializer.Generator" Version="2.0.0" />
  </ItemGroup>

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

</Project>

But I still see the same issue. Unfortunately, dotnet publish does not seem to want to bring over System.Xml.ReaderWriter.dll to the output directory like it did for EdgeJs once I mentioned that as a package reference.

I've also tried mentioning the reference on the javascript side like this:

const dotNetFunction = edge.func({
  assemblyFile:
    'path\\to\\my.dll',
  references: [
    'C:\\Users\\jsmith\\.nuget\\packages\\system.xml.readerwriter\\4.3.1\\lib\\netcore50\\System.Xml.ReaderWriter.dll'
  ]
});

Could I get some help getting pointed in the right direction?

Can't load Core2 dll when it has a reference

The original issue (#3) of not being able to load an core2 dll was resolved by including the following;

process.env.EDGE_USE_CORECLR=1

in my main.js.

I then created a new ClassLibrary that contained nothing but the following;

using System;

namespace Some.Library
{
    public class SomeClass
    {
        public DateTime GetDateTimeNow()
        {
            return DateTime.Now;
        }
    }
}

My Hello.Core project references the new Some.Library project and uses the SomeClass as follows;

public class Startup
    {
       // public CommandCompositionHelper CommandCompositionHelper { get; set; }

        public Startup()
        {

        }
        public async Task<object> Invoke(object input)
        {
            var dd = JsonConvert.SerializeObject("Hello from dot net core 2"); // Newtonsoft.Json.dll can be loaded.
            var pp = new SomeClass().GetDateTimeNow(); // can't load Some.Library.dll
            return dd + pp;
        }
    }

can t load some libary

Hello World!

We are using Node.js 7.9.0, Chromium 58.0.3029.110, and Electron 1.7.9.

It doesn't have a problem with Newtonsoft.Json.dll, which is not located in my bin folder. So .net core is able to load it from somewhere. However my personal helper library, Some.Library, can't be loaded.

I attached a debugger and saw that my Startup constructor is hit when I make the following call from main.js, which defers loading for my SomeLibrary.dll until its needed;

  var helloWorld = edge.func({
    assemblyFile: path.join(__dirname, '\\MEF\\Hello.Core\\bin\\Debug\\netcoreapp2.0\\Hello.Core.dll'),
    typeName: 'Hello.Core.Startup'
  });

When I make a call to;

helloWorld({
      url: 'local://v1/programs/is-installed',
      method: 'GET',
      headers: {
          'Content-Type': 'application/json',
          'X-Symc-Fetch-App-Version': '1.0'
      },
      body: {
          displayName: 'Norton Internet Security'
      }
  }, function(error, result) {
      if (error) throw error;
      console.log(result);
  });

Some.Library.dll is then required and can't be loaded.

Pre-compile for node.js version v9.8.0

I noticed you pre-compiled for node v9.8.0 17 days ago for edge-js . I have a package that has electron-edge-js as a dependent, and was hoping to find out when you might be updating this project as well for v9.8.0 support. Thanks for your help, and for keeping this project alive.

Mac os cannot find edge native module

Built app which works fine in windows environment but when building it on mac we get an error when running the start script.
Uncaught Error: The edge native module is not available at /Users/lightingreality/Documents/Macapp/node_modules/electron-edge-js/build/Release/edge_coreclr.node.
We followed the building process for mac but that doesn't seem to fix the issue.

Node 12 Heads Up

@agracio

Electron 5 will be released in 2 weeks, with Node 12 support:
https://electronjs.org/docs/tutorial/electron-timelines

In addition, Electron is transitioning into a faster release schedule, to keep up to date with latest Chromium:
https://electronjs.org/blog/electron-5-0-timeline

Which means in the foreseeable future, we will be seeing more and more Electron releases on top of Node 12, at an increased rate. Supporting Node 12 seems like an important step for future-proofing this great project.

How can I help? What needs to be done to get Node 12 support with edge-js and electron-edge-js?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.