private static Assembly LoadAssembly() { try { return(Assembly.Load("ClearScriptV8")); } catch (FileNotFoundException) { } LoadNativeLibrary(); var suffix = Environment.Is64BitProcess ? "64" : "32"; var fileName = "ClearScriptV8-" + suffix + ".dll"; var messageBuilder = new StringBuilder(); var paths = GetDirPaths().Select(dirPath => Path.Combine(dirPath, deploymentDirName, fileName)).Distinct(); foreach (var path in paths) { try { return(Assembly.LoadFrom(path)); } catch (Exception exception) { messageBuilder.AppendInvariant("\n{0}: {1}", path, MiscHelpers.EnsureNonBlank(exception.Message, "Unknown error")); } } var message = MiscHelpers.FormatInvariant("Cannot load V8 interface assembly. Load failure information for {0}:{1}", fileName, messageBuilder); throw new TypeLoadException(message); }
private static IntPtr LoadNativeLibrary() { var suffix = Environment.Is64BitProcess ? "x64" : "ia32"; var fileName = "v8-" + suffix + ".dll"; var messageBuilder = new StringBuilder(); var paths = GetDirPaths().Select(dirPath => Path.Combine(dirPath, deploymentDirName, fileName)).Distinct(); foreach (var path in paths) { var hLibrary = NativeMethods.LoadLibraryW(path); //var hLibrary = NativeMethods.UnixLoadLibrary(path, NativeMethods.RTLD_NOW); if (hLibrary != IntPtr.Zero) { return(hLibrary); } var exception = new Win32Exception(); messageBuilder.AppendInvariant("\n{0}: {1}", path, MiscHelpers.EnsureNonBlank(exception.Message, "Unknown error")); } var message = MiscHelpers.FormatInvariant("Cannot load V8 interface assembly. Load failure information for {0}:{1}", fileName, messageBuilder); throw new TypeLoadException(message); }
MemberInfo[] IReflect.GetMember(string memberName, BindingFlags bindFlags) { // This occurs during VB-based dynamic script item invocation. It was not observed // before script items gained an IReflect/IExpando implementation that exposes // script item properties as fields. Apparently VB's dynamic invocation support not // only recognizes IReflect/IExpando but actually favors it over DynamicObject. return(typeof(ScriptMethod).GetMember(MiscHelpers.EnsureNonBlank(memberName, "Invoke"), bindFlags)); }
internal ScriptInterruptedException(string engineName, string message, string errorDetails, int errorCode, bool isFatal, Exception innerException) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException) { this.engineName = engineName; this.errorDetails = MiscHelpers.EnsureNonBlank(errorDetails, base.Message); this.isFatal = isFatal; if (errorCode != 0) { HResult = errorCode; } }
internal ScriptEngineException(string engineName, string message, string errorDetails, int errorCode, bool isFatal, Exception innerException) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException) { this.engineName = engineName; // ReSharper disable once RedundantBaseQualifier this.errorDetails = MiscHelpers.EnsureNonBlank(errorDetails, base.Message); this.isFatal = isFatal; if (errorCode != 0) { HResult = errorCode; } }
internal ScriptEngineException(string engineName, string message, string errorDetails, int errorCode, bool isFatal, bool executionStarted, object scriptException, Exception innerException) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException) { this.engineName = engineName; this.errorDetails = MiscHelpers.EnsureNonBlank(errorDetails, base.Message); this.isFatal = isFatal; this.executionStarted = executionStarted; this.scriptException = scriptException; if (errorCode != 0) { HResult = errorCode; } }
private static IntPtr LoadNativeLibrary(string baseFileName) { var suffix = Environment.Is64BitProcess ? "-x64" : "-ia32"; var fileName = baseFileName + suffix + ".dll"; var messageBuilder = new StringBuilder(); IntPtr hLibrary; Win32Exception exception; var paths = GetDirPaths().Select(dirPath => Path.Combine(dirPath, deploymentDirName, fileName)).Distinct(); foreach (var path in paths) { hLibrary = NativeMethods.LoadLibraryW(path); if (hLibrary != IntPtr.Zero) { return(hLibrary); } exception = new Win32Exception(); messageBuilder.AppendInvariant("\n{0}: {1}", path, MiscHelpers.EnsureNonBlank(exception.Message, "Unknown error")); } if (string.IsNullOrEmpty(deploymentDirName)) { var systemPath = Path.Combine(Environment.SystemDirectory, fileName); hLibrary = NativeMethods.LoadLibraryW(systemPath); if (hLibrary != IntPtr.Zero) { return(hLibrary); } exception = new Win32Exception(); messageBuilder.AppendInvariant("\n{0}: {1}", systemPath, MiscHelpers.EnsureNonBlank(exception.Message, "Unknown error")); } var message = MiscHelpers.FormatInvariant("Cannot load V8 interface assembly. Load failure information for {0}:{1}", fileName, messageBuilder); throw new TypeLoadException(message); }
private static IntPtr LoadNativeLibrary(string baseFileName, string prefix, string suffix32, string suffix64, string extension) { var suffix = Environment.Is64BitProcess ? suffix64 : suffix32; var fileName = prefix + baseFileName + suffix + extension; var messageBuilder = new StringBuilder(); IntPtr hLibrary; var paths = GetDirPaths().Select(dirPath => Path.Combine(dirPath, deploymentDirName, fileName)).Distinct(); foreach (var path in paths) { hLibrary = LoadLibrary(path); if (hLibrary != IntPtr.Zero) { return(hLibrary); } messageBuilder.AppendInvariant("\n{0}: {1}", path, MiscHelpers.EnsureNonBlank(GetLoadLibraryErrorMessage(), "Unknown error")); } if (string.IsNullOrEmpty(deploymentDirName)) { var systemPath = Path.Combine(Environment.SystemDirectory, fileName); hLibrary = LoadLibrary(systemPath); if (hLibrary != IntPtr.Zero) { return(hLibrary); } messageBuilder.AppendInvariant("\n{0}: {1}", systemPath, MiscHelpers.EnsureNonBlank(GetLoadLibraryErrorMessage(), "Unknown error")); } var message = MiscHelpers.FormatInvariant("Cannot load ClearScript V8 library. Load failure information for {0}:{1}", fileName, messageBuilder); throw new TypeLoadException(message); }
/// <summary> /// Initializes a new <see cref="ScriptEngineException"/> with the specified error message and nested exception. /// </summary> /// <param name="message">The error message.</param> /// <param name="innerException">The exception that caused the current exception to be thrown.</param> public ScriptEngineException(string message, Exception innerException) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException) { // ReSharper disable once RedundantBaseQualifier errorDetails = base.Message; }
/// <summary> /// Initializes a new <see cref="ScriptEngineException"/> with the specified error message and nested exception. /// </summary> /// <param name="message">The error message.</param> /// <param name="innerException">The exception that caused the current exception to be thrown.</param> public ScriptEngineException(string message, Exception innerException) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException) { errorDetails = base.Message; }
private static Assembly LoadAssembly() { Assembly tempAssembly; if (MiscHelpers.Try(out tempAssembly, () => Assembly.Load("ClearScriptV8"))) { return(tempAssembly); } var hZlibLibrary = LoadNativeLibrary("v8-zlib"); try { var hBaseLibrary = LoadNativeLibrary("v8-base"); try { var hLibrary = LoadNativeLibrary("v8"); try { var suffix = Environment.Is64BitProcess ? "64" : "32"; var assemblyName = "ClearScriptV8-" + suffix; var fileName = assemblyName + ".dll"; var messageBuilder = new StringBuilder(); var paths = GetDirPaths().Select(dirPath => Path.Combine(dirPath, deploymentDirName, fileName)).Distinct(); foreach (var path in paths) { try { return(Assembly.LoadFrom(path)); } catch (Exception exception) { messageBuilder.AppendInvariant("\n{0}: {1}", path, MiscHelpers.EnsureNonBlank(exception.Message, "Unknown error")); } } if (string.IsNullOrEmpty(deploymentDirName)) { var publicKeyToken = typeof(V8Proxy).Assembly.GetName().GetPublicKeyToken(); if ((publicKeyToken != null) && (publicKeyToken.Length > 0)) { var assemblyFullName = MiscHelpers.FormatInvariant("{0}, Version={1}, Culture=neutral, PublicKeyToken={2}", assemblyName, ClearScriptVersion.Value, BitConverter.ToString(publicKeyToken).Replace("-", string.Empty)); try { return(Assembly.Load(assemblyFullName)); } catch (Exception exception) { messageBuilder.AppendInvariant("\n{0}: {1}", assemblyFullName, MiscHelpers.EnsureNonBlank(exception.Message, "Unknown error")); } } } var message = MiscHelpers.FormatInvariant("Cannot load V8 interface assembly. Load failure information for {0}:{1}", fileName, messageBuilder); throw new TypeLoadException(message); } finally { NativeMethods.FreeLibrary(hLibrary); } } finally { NativeMethods.FreeLibrary(hBaseLibrary); } } finally { NativeMethods.FreeLibrary(hZlibLibrary); } }
/// <summary> /// Initializes a new <see cref="ScriptInterruptedException"/> with the specified error message. /// </summary> /// <param name="message">The error message.</param> public ScriptInterruptedException(string message) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage)) { errorDetails = base.Message; }
/// <summary> /// Initializes a new <see cref="DocumentInfo"/> structure with the specified document name. /// </summary> /// <param name="name">The document name.</param> public DocumentInfo(string name) : this() { this.name = MiscHelpers.EnsureNonBlank(name, DefaultName); }
/// <summary> /// Initializes a new <see cref="ScriptInterruptedException"/> with the specified error message. /// </summary> /// <param name="message">The error message.</param> public ScriptInterruptedException(string message) : base(MiscHelpers.EnsureNonBlank(message, defaultMessage)) { // ReSharper disable once RedundantBaseQualifier errorDetails = base.Message; }