Skip to content

[OSX] ChakraCore DLL not found #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StigOlavsen opened this issue May 2, 2017 · 19 comments
Closed

[OSX] ChakraCore DLL not found #28

StigOlavsen opened this issue May 2, 2017 · 19 comments

Comments

@StigOlavsen
Copy link

StigOlavsen commented May 2, 2017

I'm having an issue where the ChakraCore DLL is not found, even if the JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 package is installed.

This is using dotnet core 1.1 with Visual Studio for Mac, same results with the dotnet cli tools.

Some minimal code to get the exception:

using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.ChakraCore;

namespace MyNamespace
{
    public class Program
    {
        public static void Main(string[] args)
        {            
            IJsEngine engine = new ChakraCoreJsEngine();
            engine.CollectGarbage();
        }
    }
}

The full exception is:

Unhandled Exception: JavaScriptEngineSwitcher.Core.JsEngineLoadException: During loading of ChakraCoreJsEngine error has occurred.	
See more details:

Unable to load DLL 'ChakraCore': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E) ---> System.DllNotFoundException: Unable to load DLL 'ChakraCore': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, JsRuntime& runtime)
   at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine.<>c__DisplayClass18_0.<.ctor>b__0()
   --- End of inner exception stack trace ---
   at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(Func`1 del)
   at PunchOutWebFrontend.Program.Main(String[] args) in /Users/steego/Dropbox/Work/DotNet/PunchOut/PunchOut.App.Web/Program.cs:line 17

The csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="React.Core" Version="3.0.1" />
    <PackageReference Include="React.AspNet" Version="3.0.1" />
    <PackageReference Include="JavaScriptEngineSwitcher.Core" Version="2.4.0" />
    <PackageReference Include="JavaScriptEngineSwitcher.Msie" Version="2.4.0" />
    <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="2.4.1" />
    <PackageReference Include="JavaScriptEngineSwitcher.Jint" Version="2.4.0" />
    <PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="2.4.1" />
    <PackageReference Include="JavaScriptEngineSwitcher.Extensions.MsDependencyInjection" Version="2.4.0" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="wwwroot\images\" />
    <Folder Include="wwwroot\js\" />
    <Folder Include="wwwroot\css\" />
  </ItemGroup>
</Project>

I'm running the project on OSX Sierra 10.12.4:

Darwin MacBook-Pro.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

The library is installed in:

~/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.1/runtimes/osx-x64/native/libChakraCore.dylib
@StigOlavsen
Copy link
Author

Could it be a case-sensitivity issue?

I notice when i delete my obj and bin folders, and then do a dotnet restore, the generated project.assets.json file has the following section

      "JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64/2.4.1": {
        "type": "package",
        "runtimeTargets": {
          "runtimes/osx-x64/native/libChakraCore.dylib": {
            "assetType": "native",
            "rid": "osx-x64"
          }
        }
      },

Which specifies JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64, while in the nuget folder it is all lowercase javascriptengineswitcher.chakracore.native.osx-x64.

@Taritsyn
Copy link
Owner

Taritsyn commented May 2, 2017

Hello, H0rdak!

I'm having an issue where the ChakraCore DLL is not found, even if the JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 package is installed.

While no one wrote about such errors. I use a similar deployment scheme in two packages: JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 and LibSassHost.Native.osx-x64.

I'm running the project on OSX Sierra 10.12.4:

Darwin MacBook-Pro.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

I have built and tested the ChakraCore on OS X El Capitan10.11.6:

Darwin Drons-Mac.local 15.6.0 Darwin Kernel Version 15.6.0: Fri Feb 17 10:21:18 PST 2017; root:xnu-3248.60.11.4.1~1/RELEASE_X86_64 x86_64

Which specifies JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64, while in the nuget folder it is all lowercase javascriptengineswitcher.chakracore.native.osx-x64.

My nuget folder is preserved case sensitive - ~/.nuget/packages/JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64. But I think, that this should not matter, because .NET Core Runtime manages independently loading of native assemblies. I just place the native assembly in runtimes/osx-x64/native directory of NuGet package.

Try to register the ChakraCore library manually:

ln -s ~/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.1/runtimes/osx-x64/native/libChakraCore.dylib /usr/local/lib/

@StigOlavsen
Copy link
Author

Thanks for your reply. I will try to manually symlink later.

Do you know where I can find any information about how dotnet core handles loading of native assemblies for nuget packages? Maybe this is an upstream bug in dotnet?

@Taritsyn
Copy link
Owner

Taritsyn commented May 2, 2017

There is very little information on this theme and part of it is already outdated: “Using native libraries in ASP.NET 5”, “Developing Libraries with Cross Platform Tools” and “.NET Core Runtime IDentifier (RID) catalog”.

@StigOlavsen
Copy link
Author

So trying with the symlink gives the same error.

Do you know if there is a way to see the filename it is trying to locate, and the search paths?

Would it give the same error if it found the file but was unable to use the library for some reason? Maybe it needs to be re-built for sierra?

@Taritsyn
Copy link
Owner

Taritsyn commented May 3, 2017

Do you know if there is a way to see the filename it is trying to locate, and the search paths?

Unfortunately, I don't know. I recommend before launching the website from the command line, execute the following commands:

export DYLD_PRINT_LIBRARIES=1
export ASPNETCORE_ENVIRONMENT=Development

Maybe it needs to be re-built for sierra?

I have no such possibility, but you can do it yourself. In the official building instructions there is not enough information yet, so use my instructions:

Install dependencies:

xcode-select --install
brew install cmake icu4c

To build the ChakraCore you must first clone the ChakraCore repository:

mkdir Github && cd Github
git clone https://github.com/Microsoft/ChakraCore.git
cd ChakraCore
git checkout v1.4.3

Run the build script:

./build.sh --icu=/usr/local/opt/icu4c/include -j=2

After the build is complete, copy libChakraCore.dylib file from ~/Github/ChakraCore/BuildLinux/Release directory to ~/.nuget/packages/JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64/2.4.1/runtimes/osx-x64/native directory.

@StigOlavsen
Copy link
Author

export DYLD_PRINT_LIBRARIES=1 this gives some more information:

dyld: loaded: /Users/user/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.1/runtimes/osx-x64/native/libChakraCore.dylib
dyld: loaded: /usr/lib/libstdc++.6.dylib
dyld: unloaded: /Users/user/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.1/runtimes/osx-x64/native/libChakraCore.dylib
dyld: unloaded: /usr/lib/libstdc++.6.dylib

Unhandled Exception: dyld: loaded: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.1.1/System.Native.dylib
JavaScriptEngineSwitcher.Core.JsEngineLoadException: During loading of ChakraCoreJsEngine error has occurred.

Followed by the same exception as before. So it looks like it finds the library, but has some problems with it. I will try building the library myself and see how that works.

@StigOlavsen
Copy link
Author

Building the library from source solved the problem.

If you or anyone else who stumbles upon this issue want to use my binary, feel free

https://www.dropbox.com/s/1guaf9ngxo2aqen/libChakraCore.dylib?dl=0

@Taritsyn
Copy link
Owner

Taritsyn commented May 3, 2017

Followed by the same exception as before. So it looks like it finds the library, but has some problems with it.

It's possible, that problem is not even in the ChakraCore library itself, but in absence of its dependencies (cmake and icu4c) on the computer. Try to roll back the ChakraCore library to version from the JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 package.

@StigOlavsen
Copy link
Author

It's possible, that problem is not even in the ChakraCore library itself, but in absence of its dependencies (cmake and icu4c) on the computer.

Both of those were already installed on my computer, so that wasn't the issue.

@Taritsyn
Copy link
Owner

@h0rdak After a series of experiments with the installation and uninstallation of libraries, I came to the conclusion, that this error was caused by the lack of the ICU4C library.

In general, problem is solved by using just one command:

brew install icu4c

@risayew
Copy link

risayew commented Sep 28, 2017

@Taritsyn I have the same problem on os x 10.12.6.
i have installed icu4c as you have mentioned above.
i have even tried the library assembly from the dropbox as @h0rdak proposed.
but still no success.
the installed nuget packages are :

<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="2.4.10" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="2.4.6" />
<PackageReference Include="JavaScriptEngineSwitcher.Core" Version="2.4.10" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="React.AspNet" Version="3.1.0" />

The exception trace:

dyld: loaded: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.0.0/System.Native.dylib
dyld: loaded: /Users/adel/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.6/runtimes/osx-x64/native/libChakraCore.dylib
dyld: loaded: /usr/lib/libstdc++.6.dylib
dyld: unloaded: /Users/adel/.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.6/runtimes/osx-x64/native/libChakraCore.dylib

Unhandled Exception: JavaScriptEngineSwitcher.Core.JsEngineLoadException: During loading of ChakraCoreJsEngine error has occurred.
See more details:

Unable to load DLL 'ChakraCore': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E) ---> System.DllNotFoundException: Unable to load DLL 'ChakraCore': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)

The most strange thing is, that it worked for the first time.
After, i've experimented with building v8 (without success)
But i can't image, that it make an influence on my problem.

Please, help.

@Taritsyn
Copy link
Owner

Hello!

i have even tried the library assembly from the dropbox as @h0rdak proposed.

I do not recommend doing this, because the native assembly may be incompatible with current version of .NET wrapper. Moreover, then problem was not in the native assembly, but in the dependencies.

The most strange thing is, that it worked for the first time.
After, i've experimented with building v8 (without success)

From this, and it was necessary to begin. If you have something worked, and then stopped working, it means that something has changed (or broken) in your operating system. I can only advise to reinstall the ICU4C library:

brew reinstall icu4c

@risayew
Copy link

risayew commented Sep 29, 2017

brew reinstall icu4c does not help.
i will try with a fresh system.

@Taritsyn
Copy link
Owner

Try to perform steps from the “Building ChakraCore > OS X > Install dependencies” section of ChakraCore's documentation.

@risayew
Copy link

risayew commented Sep 30, 2017

I tried on the fresh system.
Tried to perform the steps from install dependencies.
Still the same error: Unable to load DLL 'ChakraCore': The specified module or one of its dependencies could not be found.
Now i'm not more shure, that it "worked" before.

@risayew
Copy link

risayew commented Sep 30, 2017

However with Jint it's working well

        var engineSwitcher = JsEngineSwitcher.Instance;
        engineSwitcher.EngineFactories
            .AddJint();
        engineSwitcher.DefaultEngineName = JintJsEngine.EngineName;

@Taritsyn
Copy link
Owner

Taritsyn commented Oct 1, 2017

Now i'm not more shure, that it "worked" before.

But somehow it worked.

However with Jint it's working well

When you execute a larger amount of JS code, you can encounter serious performance issues.

@Taritsyn
Copy link
Owner

@h0rdak, @risayew This problem was solved in version 2.4.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants