Taritsyn / JavaScriptEngineSwitcher

JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines. This library allows you to quickly and easily switch to using of another JavaScript engine.
Apache License 2.0
440 stars 49 forks source link

AccessViolationException in JavaScriptEngineSwitcher.ChakraCore 2.4.3 #30

Closed defcon84 closed 7 years ago

defcon84 commented 7 years ago

When i upgrade ChakraCore (incl. native windows packages) to 2.4.3 in my project, the AccessViolationException is back. Downgrade to 2.4.2 and everything works perfectly. It seems something has changed in this version, or do i miss something on my server? (like a specific windows update?)

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsSetCurrentContext(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsContext)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine+<>c__DisplayClass22_0`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<InvokeScript>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher+<>c__DisplayClass12_0`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].<Invoke>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

project packages:

Taritsyn commented 7 years ago

Hello, Filip!

It seems something has changed in this version, or do i miss something on my server? (like a specific windows update?)

ChakraCore was updated: 1.4.4 -> 1.5.0.

It is possible, that new version of the ChakraCore conflicts with the Chakra from browser (Internet Explorer and Edge).

Try to disable usage of the JavaScriptEngineSwitcher.Msie by using the AllowMsieEngine property, or configure explicit usage of the JavaScriptEngineSwitcher.ChakraCore.

defcon84 commented 7 years ago

Forgot to tell you, i already disable MSIE this way:

JsEngineSwitcher.Instance.EngineFactories.Remove(JavaScriptEngineSwitcher.Msie.MsieJsEngine.EngineName);
JsEngineSwitcher.Instance.EngineFactories.AddChakraCore();
Taritsyn commented 7 years ago

If you did this after registering the React.NET, then these settings will not have any effect. You just need to insert the following code before registering the React.NET:

JsEngineSwitcher.Instance.EngineFactories.AddChakraCore();

And you do not need to remove anything.

Which ASP.NET framework do you use?

defcon84 commented 7 years ago

Offcourse, this is the order i do it:

JsEngineSwitcher.Instance.EngineFactories.AddChakraCore();

services.AddCors(options => .....

services.AddMvc();
services.AddReact();

I use an ASP.NET MVC Core project with the ASP.NET 4.6.2 framework. Runs on Windows Server 2012 R2 with IE 11.0.9600.18666 (update 11.0.42)

Taritsyn commented 7 years ago

Then, in your case, it's better to use the following code (read details in the “Registration of JS engines -> ASP.NET Core 1.X” section of documentation):

services.AddJsEngineSwitcher()
    .AddChakraCore()
    ;

Of course, this will not prevent error, but it would be more correct.

defcon84 commented 7 years ago

I replaced the old AddChakraCore(); with the new one. And indeed as expected, it did not fix our problem. Only thing I can do now is try and update Windows. I'll try this soon, when the acceptance server isn't used.

Taritsyn commented 7 years ago

During half an hour I will publish the fix.

Taritsyn commented 7 years ago

Try upgrading to version 2.4.4. Packages with native assemblies has not changed.

defcon84 commented 7 years ago

It seems to be fixed! Thank you very much!