Ejemplo n.º 1
0
        /// <summary>
        ///     This is the main method to call to resolve all dependencies. This MUST be the first method called, which is
        ///     automatically called by the V8Engine's static constructor. You can also call this directly in a "main" or "startup"
        ///     file before touching any V8.Net type.
        /// </summary>
        public static void ResolveDependencies()
        {
            _CheckLocalPathUpdated();

            // ... force load the required assemblies now (this is assuming the method is called from the calling type's static constructor or main startup) ...

            //if (!IsLoaded("V8.Net.SharedTypes"))
            //    Assembly.Load("V8.Net.SharedTypes");

            //if (Environment.Is64BitProcess)
            //{
            //    if (!IsLoaded("V8.Net.Proxy.Interface.x64"))
            //        Assembly.Load("V8.Net.Proxy.Interface.x64");
            //}
            //else
            //{
            //    if (!IsLoaded("V8.Net.Proxy.Interface.x86"))
            //        Assembly.Load("V8.Net.Proxy.Interface.x86");
            //}

            //if (!IsLoaded("V8.Net"))
            //    Assembly.Load("V8.Net");

            var paths = ValidPaths.ToArray();

            foreach (var path in paths)
                if (TryLoad(path))
                    return;

            var bitStr = Environment.Is64BitProcess ? "x64" : "x86";
            var msg = $"Could not locate the required V8 native libraries.  V8.NET is running in the '" + bitStr + "' mode.  Some areas to check: " + Environment.NewLine
                + "1. Did you download the DLLs from a ZIP file? If so you may have to unblock the file. On Windows, you must open the file properties of the zip file and 'Unblock' it BEFORE extracting the files." + Environment.NewLine
                + "2. Review the searched paths in the nested errors below and make sure the desired path is accessible to the application ";

            if (!string.IsNullOrWhiteSpace(_WebHostPath))
                msg += "pool identity (usually Read & Execute for 'IIS_IUSRS', or a similar user/group)" + Environment.NewLine;
            else
                msg += "for loading the required libraries under the current program's security context." + Environment.NewLine;

            msg += " Paths searched: " + Environment.NewLine + " * " + string.Join(Environment.NewLine + " * ", paths);

            System.Diagnostics.Debug.WriteLine(msg, "WARNING");

            if (Environment.UserInteractive)
                Console.WriteLine(msg);

            if (System.Diagnostics.Debugger.IsAttached)
                throw new DllNotFoundException(msg + Environment.NewLine + "This exception is thrown as a notice since a debugger is attached. You can always use a try..catch block to ignore it.");
        }
Ejemplo n.º 2
0
        static void _CheckLocalPathUpdated()
        {
            if (!_LocalPathEnvUpdated)
            {
                try
                {
                    // ... add the search location to the path so "Assembly.LoadFrom()" can find other dependant assemblies if needed ...
                    // ... attempt to update environment variable automatically for the native DLLs ...
                    // (see: http://stackoverflow.com/questions/7996263/how-do-i-get-iis-to-load-a-native-dll-referenced-by-my-wcf-service
                    //   and http://stackoverflow.com/questions/344608/unmanaged-dlls-fail-to-load-on-asp-net-server)

                    var path     = System.Environment.GetEnvironmentVariable("PATH"); // TODO: Detect other systems if necessary.
                    var newPaths = string.Join(";", ValidPaths.ToArray()) + ";";
                    System.Environment.SetEnvironmentVariable("PATH", newPaths + path);
                    _LocalPathEnvUpdated = true;
                }
                catch { }
            }
        }