microsoft.clearscript.v8 in use promise but this code in error return

169 views Asked by At

In this code I am using microsoft.clearscript.v8 library in c# (asp .net core mvc)

how to solve this error '((Microsoft.ClearScript.ScriptItem)promiseResult).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException' in server side javascript run on asp .net core mvc

this below code is Home controller in call js file()

public IActionResult Index()
    {

        using (var engine = new V8ScriptEngine())
        {
            
            engine.AddHostType("Console", typeof(Console));           

            string scriptPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "js", "NewScript.js");
            string scriptContent = System.IO.File.ReadAllText(scriptPath);
            engine.Execute(scriptContent);
            
            try
            {
               
                dynamic promiseResult = engine.Script.newfunction();                   

               ViewBag.Result = promiseResult;
               
            }
            catch (Exception ex)
            {
                // Handle exceptions if the promise is rejected
                string result = $"Error: {ex.Message}";
                ViewBag.Result = result;
            }

         
        }
   }

this below code in Javascript NewScript.js

function newfunction() {    
const promise1 = Promise.resolve("This is promised 1");

    promise1.then((value1) => {        
       return value1;        
   });

}

this newfunction return this {[undefined]} or {Microsoft.ClearScript.V8.V8ScriptItem.V8ScriptObject}

get this error UnderlyingSystemType = '((Microsoft.ClearScript.ScriptItem)promiseResult).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException'

0

There are 0 answers