javascriptc#jint

Calling an external JS library function with C#


I am trying to load an external javascript file (http://turfjs.org/ a geospatial library I want to use within C#) and call a function (in my example turf.distance) I am using the code below using Jint but I got an exception Can you help me? Thank you

String path = "turf.min.js";
String jsContent=File.ReadAllText(path);
try
{
    var script = new Engine()
    .Execute(jsContent)
    .GetValue("turf.distance");
    var result = script.Invoke(43.625, 3.61815, 43.6267, 3.60394);
}
catch (Exception exception)
{
    // got an "Instance Error" (see image for details)
}

enter image description here


Solution

  • Answer has been given on github (https://github.com/Turfjs/turf/) by the API creator who has been very efficient and available for solving this issue.