Bundling Visual C++ dlls along with ClearScript

Jul 20, 2016 at 9:15 PM
Could someone please point out the specific Visual C++ Redistributable dll's that needs to be bundled with a project using ClearScript v5.4.2.1?

I understand that ClearScript depends on Visual C++ Redistributable installed on the target machine, but simply installing the distributable from https://www.microsoft.com/en-us/download/details.aspx?id=40784 did not fix the issues with loading ClearScriptV8 dlls.

I tried building a Winforms based .Net45 application targeting x86, x64 and Any Platform target and I installed both x86 and x64 versions of the Visual C++ redistributable from the link above on a machine running win7 professional. However, I still run into Could not load file or assembly ClearScriptv8-32.DLL or Could not load file or assembly ClearScriptv8-64.DLL error based on build format I ran. Wondering if a machine needs to be restarted after installing Visual C++ redistributable package?

I am trying to find out how each one of you enforce the Visual C++ redistributable dependency on a Windows App based solution that uses ClearScript and have you run into issues similar to what I am seeing?
Jul 20, 2016 at 10:05 PM
Hi i2infinity,

Like most applications with C++ components, ClearScript requires C++ libraries that match the tools that built it.

From the ClearScript ReadMe:

IMPORTANT: If Visual Studio is not installed on your deployment machine, you must install 32-bit and 64-bit Visual C++ Redistributable packages:

Visual Studio 2013

Visual Studio 2015

If you know which Visual Studio version was used to build your copy of ClearScript, use the appropriate link above. If not, try installing both. If you're deploying a debug build of ClearScript, see here.

Good luck!
Jul 20, 2016 at 10:49 PM
Edited Jul 20, 2016 at 11:07 PM
Thanks for getting back.

Is there any other way to manually reference only the required Visual C++ DLLs in my project and has someone done it successfully? Preparing each one of the deployment machine by installing 4 different versions of Visual C++ redistributable (x86 and x64 for 2013 and 2015) is going to be a pain for big scale installs.

I am using ClearScript v7.4.2.1 from here https://www.nuget.org/packages/ClearScript.V8/ . How would I find out which version of Visual Studio was used to build ClearScript?

By If you know which Visual Studio version was used to build your copy of ClearScript, use the appropriate link above, I assume you were pointing to visual studio version that was used to build ClearScript binaries and not my App that references ClearScript.
Jul 20, 2016 at 11:33 PM
Hi again,

How are you deploying your application? Are you using a Windows Installer package? If so, you can include the Visual C++ libraries in the package. Have a look here for more information.

To find out how a given NuGet package was built, we recommend contacting the package owners. The link for this particular package is here.

Jul 21, 2016 at 12:30 AM
Edited Jul 21, 2016 at 12:32 AM
I don't actually distribute the App. We are developing a Point of Sale SDK that uses ClearScript and distribute the SDK as a nuget package to our partners who use it on their Apps. Previously we used JINT and we bundled all required DLLs directly into the nuget package and now that we are moving to ClearScript v5.4.2.1, our partners ran into all these DLL cannot be loaded issue even after installing Visual C++ redistributable 2013 & 2015 (both x86 and x64). The App was build targeting Any Platform with Prefer 32 Bit not set

It will be so much easier if we could just cherry pick the required DLLs and bundle them with our nuget release
Jul 21, 2016 at 5:26 PM
Edited Jul 21, 2016 at 5:27 PM
Hi i2infinity,

First, we encourage you to build ClearScript yourself via the walkthrough in the ReadMe. That way there'll be no confusion about which libraries to include with your SDK, and you'll get newer and faster versions of ClearScript and V8.

Next, since you wish to bundle the Visual C++ libraries with your SDK rather than install the redistributable packages, you'll have to deal with the platform issue (32-bit vs. 64-bit), as the files for both platforms are named identically.

Here's one way to do it. Have your SDK set up the following directory structure on the target machine:
The 32-bit and 64-bit versions of the Visual C++ libraries (concrt140.dll, msvcp140.dll, vccorlib140.dll, and vcruntime140.dll) can be found in your Visual C++ installation directory. Some typical paths:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x86\Microsoft.VC140.CRT\
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x64\Microsoft.VC140.CRT\
Finally, to ensure proper loading of the platform-specific ClearScript and V8 libraries, add the following code to your SDK and invoke it before creating your first V8 runtime or engine instance:
private static void InitClearScript() {
    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
        if (args.Name != "ClearScriptV8")
            return null;
        var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        var bits = Environment.Is64BitProcess ? "64" : "32";
        return Assembly.LoadFrom(Path.Combine(path, bits, "ClearScriptV8-" + bits + ".dll"));
Of course you can customize this hook to load the libraries from any desired location.

Good luck!
Jul 21, 2016 at 11:10 PM
Thanks a bunch. Let me try this out and get back