Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

New Post: Exception propagation from C# to Javascript

$
0
0
Hi,

I tried err.hostException, but this came as null.

I then added HostFunctions as host object and tried your next suggestion. But looks like HostFunctions does not have tryCatch().
My Clearscript version is : 5.3.10.0

I tried Like below:
-------adding HostFunctions to engine----------
engine.AddHostObject("host", new HostFunctions());

In javascript

var succeeded = host.tryCatch(
    function() {
        loginResponse = httpclient.Post(url,payload);
    },
    function(exception) {
        hostException = exception;
        return true;
    }
);
if (succeeded) {    
    Log.Info('SUCCESS');
}
else {
    Log.Error('err msg...' + hostException.Message);
    Log.Error('err type...' + hostException.GetBaseException().ToString());
}

This fails saying "Microsoft.ClearScript.ScriptEngineException: TypeError: Object #<HostObject> has no method 'tryCatch'"

Is it what you were suggesting ?

New Post: Exception propagation from C# to Javascript

$
0
0
Hi,

I guess will need to upgrade, came to know from your responses @
related post...


Thanks for your suggestions :)...

New Post: Exception propagation from C# to Javascript

$
0
0
Hi maicalal,

Yes, unfortunately you'll have to upgrade to get the newer exception handling features.

Cheers!

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0
Hi, I am creating v8 script engine in thread and executing script. a list contains script files which are executed in thread one by one. when more number script files executed "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." exception is thrown and application gets crashed.
public async Task PlayProject(string projectData) 
{
       var engineInstance= new V8ScriptEngine();

       jsScript = File.ReadAllText(projectData);   
   
      Task.Factory.StartNew(() => {
                 var compiledScript = engineInstance.Compile(jsScript);
                engineInstance.Execute(compiledScript);     
       });    
}
Thanks
Praveen

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0
Hi Praveen,

Be sure to dispose each instance of V8ScriptEngine when you're done with it. That's absolutely essential in an application that uses multiple instances, as each one holds significant unmanaged resources that .NET's garbage collector can't track.

In addition, be careful with the number of active (undisposed) instances you have at a time. Each V8 runtime reserves a large chunk of address space, and a 32-bit process can easily reach the point of exhaustion with just a few dozen instances. For concurrent execution of multiple scripts, consider using a pool of engines, with a fixed size that's roughly equal to your CPU core count.

Good luck!

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0
Hi,

Thank you for reply. I implemented engine pool as as you suggested using ClearScript.Manager and exception is still happens and application gets crashed. this happens when script file list grows to 100-300 scripts. it executes success fully when we have few scripts files to execute. My script contains winform object,threads task and many other 3rd party component objects. Is it better to use multi process architecture for this kind of problems. so that only child process appdomain gets killed.
public async Task PlayProject(string projectData) 
{
       var engineInstance= new V8ScriptEngine();

       jsScript = File.ReadAllText(projectData);   
   
      Task.Factory.StartNew(() => {

                //__Start new child process from here__

                 var compiledScript = engineInstance.Compile(jsScript);
                engineInstance.Execute(compiledScript);     
       });    
}
Thanks
Praveen

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0
Hi Praveen,

It's difficult to diagnose your issue without more information, but if the crash happens during V8ScriptEngine construction, then it's nearly certain that you're running out of address space by creating too many active instances.

One of our pre-release tests is to run the SunSpider suite thousands of times within a single process, each in a separate V8ScriptEngine instance. As long as you dispose each instance when you're done with it, and you don't try to use a large number of instances concurrently, you should be OK.

If that's not how your application is crashing, we'll be happy to look at a stack trace or try to reproduce the crash if you can share some more of your code or a minimal crashing sample.

Cheers!

New Post: Returning syntax error location

$
0
0
Hi,

I seem to have the same problem.
I adapted the basic module loader of node.js (native_module.js). Loading a module will call into a run method in the JavaScript module implementation. This in turn calls back into c# to finally execute the code on the engine.
Doing this however does not give us useful information like position in case of syntax errors in the module to be loaded:
SyntaxError: Unexpected token ILLEGAL
    at NativeModule.run (snp_native_module.js [temp]:140:41) -> exports.checkMeasurement = function (measurement) {§
    at NativeModule.run (snp_native_module.js [temp]:65:22)
The wrong token $ is not in snp_native_module.js. But 140:41 in snp_native_module.js is the location where I call back to c# to execute the module.

Currently we use version 5.4.5.
Is this already fixed in 5.4.6? Or is there any workaround?

New Post: Returning syntax error location

$
0
0
Hi ZoneRunner,

Are you seeing this with JScript/VBScript or V8?

Thanks!

New Post: Returning syntax error location

New Post: Returning syntax error location

$
0
0
Hi again,

Exceptions thrown from V8ScriptEngine, even when passing though multiple host-to-script transitions, should be linked to the root exception via InnerException. Try traversing the exception chain, or calling GetBaseException, to get to the one that corresponds to the syntax error. That should contain all the information that V8 provides.

Good luck!

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0
Hi,

Please find my application sample to recreate above issue. I also included memory leak script.

Thanks
Praveen

New Post: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

$
0
0
Hi again,

Thanks for sharing your sample!

In our tests, your application crashes even when the iteration count is set to 1. The script attempts to create an array of 1,000 strings, each of length 1,000,000 characters. With default settings, V8 simply can't do this in a 32-bit process; it runs out of memory and kills the process. It might be possible to use resource constraints to expand V8's limits, but no amount of tweaking is likely to make this particular script work.

A 64-bit process is able to complete this script, ending up with a working set of around 1.3 GB.

Cheers!

New Post: Returning syntax error location

$
0
0
Hi,

well it seems the problem is not as easy to describe as I hoped so I have build a small example:
public class Program
{
    static void Main(string[] args)
    {
        try
        {
            var host = new ScriptHost();
            dynamic result = host.LoadModule();
            Console.WriteLine(result.content);
        }
        catch (Exception ex)
        {
            // (0)
            throw;
        }
    }
}

public class ScriptHost
{
    private V8ScriptEngine _engine = new V8ScriptEngine("MyEngine");
    private dynamic _moduleLoader;

    public ScriptHost()
    {
        var moduleLoaderSource = @"(function loadModule(host, name, source) { return host.Run(name, source); })";
        _moduleLoader = _engine.Evaluate("module_loader.js", moduleLoaderSource);
    }

    public object LoadModule()
    {
        var someModuleSource = @"({ content: 'There is a syntax error in this module.'§ })";
        return _moduleLoader(this, "some_module.js", someModuleSource);
    }

    public object Run(string name, string source)
    {
        try
        {
            return _engine.Evaluate(name, source);
        }
        catch (Exception ex)
        {
            // (1)
            throw;
        }
    }
}
Now let's look at the ErrorDetail property of the two exceptions (1) and (2):
(1)
"SyntaxError: Invalid or unexpected token
    at loadModule (module_loader.js [temp]:1:56) -> ({ content: 'There is a syntax error in this module.'§ })"
The stacktrace looks confusing here. While the given source code is indeed the syntax error, it claims that this line is in module_loader.js [temp]:1:56 which is wrong.
(2)
"Error: SyntaxError: Invalid or unexpected token
    at loadModule (module_loader.js [temp]:1:56) -> (function loadModule(host, name, source) { return host.Run(name, source); })"
Ok, now the given source code corresponds to the location. However, that only means that now both are wrong. Much less problematic but also strange: The new "Error:" prefix that was not part of the messsage at (1).

Ideally I would expect a stacktrace like this:
"SyntaxError: Invalid or unexpected token
    at (some_module.js [temp]:1:53) -> ({ content: 'There is a syntax error in this module.'§ })"
    at loadModule (module_loader.js [temp]:1:56)"

New Post: Returning syntax error location

$
0
0
Hi ZoneRunner,

Thanks for posting your sample code!

The detail text of exception 1 does appear to be formatted incorrectly. When V8 initially reports the syntax error, ClearScript is confused by the presence of a stack trace, since script code with syntax errors isn't executable. ClearScript's assumption is incorrect in cases involving nested invocations of the script engine.

The outer exception (exception 2) is correct, however. The syntax error passes through the host, where it's wrapped in a host exception, and as is the case with all host exceptions, it's passed back to the outer script frame as a JavaScript object of type Error, whose constructor adds the "Error: " prefix.

ClearScript's next point release will include a fix for the formatting of the inner exception's detail text. With the fix, the inner exception will look exactly as you suggest; its detail text will include the location of the syntax error as well as the stack traces of any outer script frames.

Thanks again!

New Post: Returning syntax error location

New Post: Bundling Visual C++ dlls along with ClearScript

$
0
0
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?

New Post: Bundling Visual C++ dlls along with ClearScript

$
0
0
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
http://www.microsoft.com/en-us/download/details.aspx?id=40784

Visual Studio 2015
http://www.microsoft.com/en-us/download/details.aspx?id=48145

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!

New Post: Bundling Visual C++ dlls along with ClearScript

$
0
0
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/5.4.2.1 . 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.

New Post: Bundling Visual C++ dlls along with ClearScript

$
0
0
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.

Cheers!
Viewing all 2297 articles
Browse latest View live




Latest Images