Closed harlankoehn closed 7 months ago
Hello @harlankoehn and @agracio ! By any chance, did you find a solution to this issue? I am experiencing the same issue only after packaging. I am running electron-builder, and everything works in developer builds. I have the C# published project folder set in extraResources. I'm on .NET 6.0, but netcoreapp3.1
also does not seem to work. I have followed the standalone instructions in edge.js's readme regarding adding the PackageReferences and PropertyGroup item. I'm dotnet publishing with runtime win-x64
and self-contained
. The environment variables are the following:
EDGE_USE_CORECLR: 1
EDGE_APP_ROOT: C:\Users\tj_co\source\repos\paranext-core\release\build\win-unpacked\resources\c-sharp\bin\Release\net6.0\publish\win-x64 (Correct, and the C# published project is at this location)
EDGE_BOOTSTRAP_DIR: C:\Users\tj_co\source\repos\paranext-core\release\build\win-unpacked\resources\app.asar\node_modules\electron-edge-js\lib\bootstrap\obj\Release\netcoreapp1.1 (without setting this, it is undefined in production. So I set it, but it doesn't seem to do anything)
And I receive the following error no matter what I do in playing with various publishing or packaging settings:
Error invoking remote method 'electronAPI.edge.invoke': System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
Following is a printout of the files in the EDGE_APP_ROOT
folder (the C# project I'm using is EdgeLibrary.csproj
):
And following is a printout of the files in the EDGE_APP_ROOT/refs
folder:
Here is my repo on the current commit: https://github.com/paranext/paranext-core/tree/d1a6a02d48602283ff7b4b542c505f9503593ec7
Thank you very much for the help! Please let me know if you have any ideas.
EDIT: I printed the stack trace of the edge code where it was throwing this "parent does not exist" stuff (note that 'electronAPI.edge.invoke' is the ipc channel for edge stuff as I have change to using a preload and nodeIntegration
off. As such, the edge code is running in main.ts
):
Error invoking remote method 'electronAPI.edge.invoke': Error: System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
Stack Trace:
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at ClrFuncReflectionWrap.Create(Assembly assembly, String typeName, String methodName)
at ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info).
This exception is thrown during edge.func
as I have here (in my main.ts
file):
edge.func({
assemblyFile: baseDll,
typeName: `${ns}.${className}`,
methodName: method,
})
I have tried importing edge
with require
as in the quickstart and with import('electron-edge-js')
as a dynamic import (with edge.func
waiting until the dynamic import is finished. I have tried setting the .csproj
dependencies to the same as in the quickstart.
Because the standalone instructions in edge.js's readme say to use netcoreapp2.1
, I have also tried that. Strangely, I get a slightly different exception as follows:
Error invoking remote method 'electronAPI.edge.invoke': Error: System.BadImageFormatException: Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Stack Trace:
at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at ClrFuncReflectionWrap.Create(Assembly assembly, String typeName, String methodName)
at ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info).
I also ran the production build while logging some kind of dll interaction using a tool called Fusion++, and that indicated an error with edge_nativeclr
:
Reproduced from the error log is the following critical piece:
LOG: Attempting download of new URL file:///C:/Users/tj_co/source/repos/paranext-core/release/build/win-unpacked/edge_nativeclr.DLL.
LOG: Attempting download of new URL file:///C:/Users/tj_co/source/repos/paranext-core/release/build/win-unpacked/edge_nativeclr/edge_nativeclr.DLL.
LOG: Attempting download of new URL file:///C:/Users/tj_co/source/repos/paranext-core/release/build/win-unpacked/edge_nativeclr.EXE.
LOG: Attempting download of new URL file:///C:/Users/tj_co/source/repos/paranext-core/release/build/win-unpacked/edge_nativeclr/edge_nativeclr.EXE.
LOG: All probing URLs attempted and failed.
I suppose edge_nativeclr.DLL
and edge_nativeclr.EXE
are some kind of intermediate files because I cannot find them anywhere. I don't know if this is helpful information, but I figured I would include it in case it means something to you. :)
In my case we resorted to building a console app which references our DLL. Then we have to call that console application with some parameters from within Electron. We were able to package the console application as a stand alone executable but we had to use the Publish feature in Visual Studio to get it to bundle correctly into one file. Nothing ideal about what we resorted to but it does work.
We were hoping to distribute our Electron app along with our .NET DLL and without any requirements to install any .NET Frameworks. So far, I haven't been able to achieve this.
As a test, I've written a small desktop app that utilizes this exact same DLL file, published it, and ran it on a clean Win10 VM that doesn't have any .NET frameworks installed. It runs without any problems.
When I take the DLL, copy over the same supporting DLL files needed by the desktop app, and also include a [projectname].deps.json file, and then run the Electron app, I get this error message:
With: process.env.EDGE_USE_CORECLR = 1
Unhandled Exception Error: This 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. at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
Without any process.env.EDGE_USE_CORECLR statement
We get this:
System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
Or this:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
Our DLL project file looks like this:
I've attached a screenshot of our DLL publish settings. This just produces a NUPKG file that when expanded, doesn't include any of the supporting DLL's needed.
Just to reiterate, how can we call functions in a .NET 5.0 or 6.0 DLL without having to install any .NET framework on the target machine? Would we have better luck if we targeted .NET 4.6 or some older version of .NET Core? Is this a problem in Edge or a problem with .NET Core? Also, do we need to target "Any CPU", "Win-x86" or "Win-x64"? We currently only need our Electron app to work on Windows but we intend to support both 32bit and 64bit versions.