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://stackoverflow.com/a/12431435/712700

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?

Community
  • 1
  • 1
goamn
  • 1,939
  • 2
  • 23
  • 39
  • You could try a different embedded engine? http://stackoverflow.com/questions/172753/embedding-javascript-engine-into-net-c – Marc Gravell Apr 18 '13 at 06:21

1 Answers1

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

Patrick D'Souza
  • 3,491
  • 2
  • 22
  • 39
  • 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. – goamn Apr 18 '13 at 07:46
  • You need the x64 version, which I don't think exists. – Brain2000 Apr 05 '17 at 21:20