Calling the Javascript functions inside C# for a 64 bit project
Asked Answered
W

1

0

I am trying to call the Javascript function "eval" from inside C# code (to utilise the string to operators parser). I used the following code: https://mcmap.net/q/146374/-calculate-result-from-a-string-expression-dynamically

It crashes though with the following message--- :

Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

I believe the problem is because the project/machine is 64 bit. I do not want to change the project to 32 bit, is there another CLSID I can use to make it work with 64 bit? Or is there another approach to simply utilise the "eval" function from Javascript within C# code?

Workwoman answered 18/4, 2013 at 6:15 Comment(1)
You could try a different embedded engine? #173253Stump
G
1

You are referring to the following code

Type scriptType = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));

dynamic obj = Activator.CreateInstance(scriptType, false);
obj.Language = "javascript";

var res = obj.Eval("a=3; 2*a+32-Math.sin(6)");

The above ClSID is actually for the ScriptControl

From the 2 above links you will see that this is VB6 related and if you want to use the code above as mentioned in your question you will need msscript.ocx. Please check if you have this file. You may have to register it correctly using regsvr32

I am using a 64-bit machine and I see the file in the following folder C:\Windows\SysWOW64

Gensmer answered 18/4, 2013 at 7:7 Comment(2)
Thanks for that, I have the file in the same location as you. I referenced it in my project and also registered it with regsvr32, I still get the same error unfortunately.Workwoman
You need the x64 version, which I don't think exists.Franko

© 2022 - 2024 — McMap. All rights reserved.