microsoft / ClearScript

A library for adding scripting to .NET applications. Supports V8 (Windows, Linux, macOS) and JScript/VBScript (Windows).
https://microsoft.github.io/ClearScript/
MIT License
1.77k stars 148 forks source link

System.TypeLoadException has been Thrown When running a ClearScript Engine #528

Closed eliashezron closed 1 year ago

eliashezron commented 1 year ago

I am failing to run a basic ClearScript Engine. I keep getting this error, What could be the problem

Screenshot 2023-07-27 at 15 43 31

ClearScriptLib commented 1 year ago

Hii @eliashezron,

I keep getting this error, What could be the problem

Please let us know how you integrated ClearScript into your project.

Also, it looks like you've resolved the compilation problem you reported in Issue #527. Is that correct?

Thanks!

eliashezron commented 1 year ago

Hii @eliashezron,

I keep getting this error, What could be the problem

Please let us know how you integrated ClearScript into your project.

Also, it looks like you've resolved the compilation problem you reported in Issue #527. Is that correct?

Thanks!

No, I didnt resolve issue#527, I just here using the debug UI,

Also, I am basically running the example here

The issue is basically at instantiating of the V8JS engine.

To replicate, I am using Vistual studio on MacBook M2 pro

here is the code

using Microsoft.ClearScript;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.V8;
namespace JsTest
{

    class Program
{
    static void Main(string[] args)
    {
        // create a script engine

        using (var engine = new V8ScriptEngine())
        {

            // expose a host type

            engine.AddHostType("Console", typeof(Console));

            engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)");
        }
     }
}
ClearScriptLib commented 1 year ago

I am using Vistual studio on MacBook M2 pro

We need to understand how you're adding ClearScript to your project. Can you post your .csproj file?

Thanks!

eliashezron commented 1 year ago

I am using Vistual studio on MacBook M2 pro

We need to understand how you're adding ClearScript to your project. Can you post your .csproj file?

Thanks!

This is my file structure, I did install the dependencies using Nuget.

Screenshot 2023-08-06 at 17 08 24
ClearScriptLib commented 1 year ago

Hi @eliashezron,

The TypeLoadException above indicates that your test app is running in x64 emulation (Rosetta). Please try adding the Microsoft.ClearScript.osx-x64 package.

Cheers!

eliashezron commented 1 year ago

Hi @eliashezron,

The TypeLoadException above indicates that your test app is running in x64 emulation (Rosetta). Please try adding the Microsoft.ClearScript.osx-x64 package.

Cheers!

This solution worked for me, Thank you.