ChakraCore.dll Exception when deployed to Azure Web App

678 Views Asked by At

I have an app which uses the Babel to transpile some dynamic JS into es5 compatible JS for use in IE browsers.

This setup works perfectly locally however once deployed to Azure I keep getting the following exception when trying to call

var babel = ReactEnvironment.Current.Babel;

Exception triggered:

React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.ReactEnvironment (Error getting vue module script) ---> React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.JavaScriptEngineFactory ---> JavaScriptEngineSwitcher.Core.JsEngineLoadException: Failed to create instance of the ChakraCoreJsEngine. Most likely it happened, because the 'ChakraCore.dll' assembly or one of its dependencies was not found. Try to install the JavaScriptEngineSwitcher.ChakraCore.Native.win-x86 package via NuGet. In addition, you still need to install the Microsoft Visual C++ Redistributable for Visual Studio 2017 (https://www.visualstudio.com/downloads/#microsoft-visual-c-redistributable-for-visual-studio-2017). ---> System.DllNotFoundException: Unable to load DLL 'ChakraCore' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer+CustomObjectLifetimeFactory.GetObject(System.Type, React.TinyIoC.TinyIoCContainer, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.ResolveInternal(React.TinyIoC.TinyIoCContainer+TypeRegistration, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.Resolve(System.Type)
at React.TinyIoC.TinyIoCContainer.Resolve()
at App.Controllers.ComponentController+<ModuleRegistrationIE11>d__4.MoveNext()
--- End of inner exception stack trace ---
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer+SingletonFactory.GetObject(System.Type, React.TinyIoC.TinyIoCContainer, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.ResolveInternal(React.TinyIoC.TinyIoCContainer+TypeRegistration, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
--- End of inner exception stack trace ---
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine..ctor(JavaScriptEngineSwitcher.ChakraCore.ChakraCoreSettings)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngineFactory.CreateEngine()
at JSPool.JsPool`2.CreateEngine()
at JSPool.JsPool`2.PopulateEngines()
at JSPool.JsPool`2..ctor()
at React.JavaScriptEngineFactory.CreatePool()
at React.JavaScriptEngineFactory..ctor(JavaScriptEngineSwitcher.Core.IJsEngineSwitcher, React.IReactSiteConfiguration, React.ICache, React.IFileSystem)
at lambda_method(System.Runtime.CompilerServices.Closure, System.Object[])
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
--- End of inner exception stack trace ---
at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsCreateRuntime(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsRuntimeAttributes, JavaScriptEngineSwitcher.ChakraCore.JsRt.JsThreadServiceCallback, JavaScriptEngineSwitcher.ChakraCore.JsRt.JsRuntime&)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine+<>c__DisplayClass10_1.<.ctor>b__0()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher+<>c__DisplayClass11_0.<Invoke>b__0()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(System.Func`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]])
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(System.Action)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine..ctor(JavaScriptEngineSwitcher.ChakraCore.ChakraCoreSettings)

The exception suggests that the ChakraCore.dll is most likely missing or the C++ Redistributable for Visual Studio 2017 is. I assume the redistributable is present in Azure becasue of this https://feedback.azure.com/forums/355860-azure-functions/suggestions/31130971-install-visual-c-2015-or-2017-redistributale?

The ChakraCore.dll appears to be present when inspecting the files in Azure enter image description here

I've also tried the suggestions here uninstalling and reinsatalling all of the relevant packages https://github.com/reactjs/React.NET/issues/400

2

There are 2 best solutions below

1
On BEST ANSWER

Ok so thanks to some desperate trial and error it was simply a case of adding support for other platforms regarding the JavaScriptEngineSwitcher.ChakraCore.Native package, I originally had just the win-x64 but installing the win-x86 as well sorted it and got it working in Azure.

This was the end result for the packages I had installed to get my app successfully working in Azure:

<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="3.1.1" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.1.1" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" Version="3.1.1" />
<PackageReference Include="JavaScriptEngineSwitcher.Core" Version="3.1.0" />
<PackageReference Include="JavaScriptEngineSwitcher.Extensions.MsDependencyInjection" Version="3.1.0" />
<PackageReference Include="JSPool" Version="4.0.0" />
0
On

I ran into this as well, and after reading the other answer, I realized that this is most likely because of the configuration in the App Service is set to 32 Bit instead of 64 Bit. After changing the config to 64 Bit, the error went away for me. Not sure about everyone else's case, but for me, instead of changing code, I made our environment match what the code wanted.

  1. Navigate to your Web App in the Azure Portal
  2. Click Configuration
  3. Click "General Settings" tab at the top.
  4. Under platform, change to 64 Bit.
  5. Click Save (doing so will restart your app and apply settings)