How can I use Edge.js with .NET version 6.0 ( or 7.0 ) and Node.js version v16.18.0?
After installing Edge.js using nuget ( dotnet add package EdgeJs --version 11.15.0 ) and importing it into my .csproj ( ) I wanna use it ( using EdgeJs; || using Edge ) but getting an error:
The type or namespace name 'EdgeJs' could not be found (are you missing a using directive or an assembly reference?).
The original Edge.js by Tomasz Tjanczuk was last updated in 2017 and doesn't support the latest versions of .NET. It will still work in a .NET Framework app on Windows, and the inline code in the original documentation to call from C# into JavaScript still works in such an application. The latest version is 8.2.1.
There is a fork of the original project which is maintained and DOES support .NET 6.0. However, for .NET 6.0 and later you cannot call from C# into JavaScript using this project I think. The only direction of travel is to call from JavaScript to C# (and back to JavaScript). This doesn't need the NuGet package, just the npm package.
I got calls working from JavaScript to .NET 7.0 using the forked npm package and node.js 16.18.0 on Windows. The steps to do this are below:
npm i [email protected]node main.jsin the command prompt/terminalYou should get output, coming from the C# function, of '.NET 7 welcomes Node.Js'. If you get a 'Could not load file or assembly' error check the Base DLL path is correct.
The same code as above works for .NET 6 as well. I have only tested this works on Windows, but the readme suggests it should work on Linux and MacOS for .NET 6.