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

System.AccessViolationException in JavascriptEngineSwitcher.ChakraCore #45

Closed bbsdddougla closed 6 years ago

bbsdddougla commented 6 years ago

We're using ReactJs.Net on top of JavascriptEngineSwitcher.ChakraCore. Everything works ok on our Win10 dev boxes and our Server 2012r2 CI. However, when deploying to server 2016 we get this error whenever we try to load a view which uses ReactJs.Net on it:

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsGetAndClearExceptionWithMetadata(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsValue ByRef)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorHelpers.ThrowIfError(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsErrorCode)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.JsContext.RunScript(System.String, JavaScriptEngineSwitcher.ChakraCore.JsRt.JsSourceContext, System.String)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine+<>c__DisplayClass45_0.<InnerExecute>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher+<>c__DisplayClass13_0.<Invoke>b__0()
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
   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()
Faulting application name: w3wp.exe, version: 10.0.14393.0, time stamp: 0x57899b8a
Faulting module name: ChakraCore.DLL, version: 1.5.2.0, time stamp: 0x5943974b
Exception code: 0xc0000005
Fault offset: 0x00000000002e4533
Faulting process id: 0x209c
Faulting application start time: 0x01d3a859ab0b300d
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: PathToWebsiteRoot\bin\x64\ChakraCore.DLL
Report Id: 63809af6-813a-4332-a20a-ba3386c07d16
Faulting package full name: 
Faulting package-relative application ID: 

We're Running on .Net Framework 4.7.1

Taritsyn commented 6 years ago

OK. Tomorrow I will try to fix.

bbsdddougla commented 6 years ago

@Taritsyn Thanks for your quick response! Let me know if there is anything else I can provide to help you troubleshoot.

Taritsyn commented 6 years ago

Just in case, check two things:

  1. Whether the Visual C++ Redistributable for Visual Studio 2015 is installed on the server.
  2. Is ChakraCoreJsEngine explicitly registered as default engine (see a “Registration of JS engines” section of documentation), because there may be a conflict between the JavaScriptEngineSwitcher.ChakraCore and JavaScriptEngineSwitcher.Msie.
bbsdddougla commented 6 years ago
  1. Yes, MS Visual C++ 2015 Redistributable 14.0.23026 is installed on the server.
  2. Yes, ChakraCoreJsEngine is explicity registered as the default engine. (We had been registering the default engine before adding the engine, but switching the order of those two statements had no effect on the outcome: loading a page with React produces the System.AccessViolationException.)
var chakraCoreJsEngineFactory = new ChakraCoreJsEngineFactory();
JsEngineSwitcher.Instance.EngineFactories.Add(chakraCoreJsEngineFactory);

var defaultJsEngineName = ChakraCoreJsEngine.EngineName;
JsEngineSwitcher.Instance.DefaultEngineName = defaultJsEngineName;

We do the registration inside of the configuration method for Reactjs.net in App_Start, and both statements get logged (logging code omitted) so we know they're being called.

Taritsyn commented 6 years ago

After researching the stack trace, I not found problems at .NET code level. It is possible, that cause of error is located at level of the ChakraCore library. Therefore I updated the ChakraCore library from version 1.5.2 to 1.8.1.

I recommend you to upgrade the JavascriptEngineSwitcher.ChakraCore to version 2.4.12.

bbsdddougla commented 6 years ago

Ok, thanks for looking at it. I'll upgrade and try again. If that doesn't work, perhaps we'll try a different engine.

Taritsyn commented 6 years ago

If that doesn't work, perhaps we'll try a different.

This error can also be caused by an antivirus or a lack of memory.

bbsdddougla commented 6 years ago

I've upgraded to 2.4.12 and it appears to run fine on server 2016. Thanks for your help!

Taritsyn commented 6 years ago

Excellent!

mehmetotkun commented 6 years ago

I faced with same problem on Server 2012. I fixed with enabling 32 bit application on app pool.