Currently, I am making use of microsoft.clearscript.v8
in ASP.Net Core MVC. The following code snippet can be found in my Home controller:
public async Task<IActionResult> Index()
{
using (var engine1 = new V8ScriptEngine())
{
engine1.AddHostType(typeof(JavaScriptExtensions));
engine1.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
string scriptPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "js", "NewScript.js");
string scriptContent = System.IO.File.ReadAllText(scriptPath);
engine1.Execute(scriptContent);
dynamic data = engine1.Evaluate("NewLinq();");
return View();
}
}
The above code is located in NewScript.js file
function NewLinq() {
const rawData = [
{ "id": 1, "name": "John", "age": 25 },
{ "id": 2, "name": "Jane", "age": 30 }
];
var result = rawData.filter(person => person.age > 25);
return result;
}
An error is being thrown by the code:
UnderlyingSystemType = '((Microsoft.ClearScript.ScriptItem)data).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException'
I am seeking guidance on how to resolve this error and successfully implement linq functionality.