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

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Ok, so even though I used the NuGet Clearscript Installer package, it did not put the following in my root project directory:
  ClearScriptV8-32.dll
  ClearScriptV8-64.dll
I've got v8update.cmd building and will try again to deploy my service.

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Ok, so after deploying and see all 4 dlls in d:\home\site\wwwroot, I'm still getting the same exception up top.

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Also, the files are not in where it seems to be looking for them:

D:\Program Files (x86)\SiteExtensions\MobileServicesDotNet\1.0.450\v8-ia32.dll: The specified module could not be found
D:\Program Files (x86)\SiteExtensions\MobileServicesDotNet\1.0.450\bin\v8-ia32.dll: The specified module could not be found

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Hmm, we can't help with NuGet issues, but so far it's unclear why the site root isn't one of the directories being searched for the V8 assemblies.

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Does the Clearscript.dll look for them one level up? If so, it should work. Is there anything I could try changing in the Clearscript project, recompiling, and then redploy my Azure service?

New Post: Retrieving javascript line index during execution

$
0
0
Is it possible to get currently executing script line number without resorting to the debugger?
I would like to highlight certain lines whenever they are being executed. For example:
public class Test() {
    public void method1(string str){};
    public void method2(string str){};
}

var engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging, port);
engine.AddHostObject("test", new Test());
engine.Execute("test_script", script_js);
script_js:
....
test.method1('foo');
....
test.method2('bar');
and I would like to retrieve the line number whenever the test.method1 or test.method2 is being executed (from within the host C# code).

What I have tried so far but without any success:
  1. V8ScriptEngine.getStackTrace() - Doesn't work since it essentially terminates the script execution.
  2. Adding
function getStackTrace(){ return new Error().stack; }
to the script and calling it from the host method e.g.
var st = (string)engine.Script.getStackTrace();
Doesn't work either. It seems to enter infinite recursive loop and just keeps calling the same host method over and over again.


Are there any other options available for V8ScriptEngine?

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Hi again,

Does the Clearscript.dll look for them one level up? If so, it should work.

ClearScript searches for the V8 assemblies as follows:
  • In the directory that contains ClearScript.dll. This is expected to fail in ASP.NET deployments due to shadow copying.
  • In AppDomain.CurrentDomain.BaseDirectory. This should be your deployment root directory, but if the exception message above is correct, it isn't being searched at all. Can you confirm that? Is the exception message exactly as shown above? If possible, try catching the exception in code to see its exact message.
  • In the directories in AppDomain.CurrentDomain.RelativeSearchPath. It looks like there might be a ClearScript bug here (it doesn't combine these paths with the deployment root path), but that shouldn't affect your scenario. Again, please verify the correctness and completeness of the exception message.
Is there anything I could try changing in the Clearscript project, recompiling, and then redploy my Azure service?

There's no need to rebuild ClearScript. You can override the V8 assembly loading procedure by using an assembly resolution hook:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
    if (args.Name == "ClearScriptV8") {
        return Assembly.LoadFrom(@"C:\Custom\Path\To\ClearScriptV8-32.dll");
    }
    returnnull;
};
Run this code once, at some point before you create your first V8ScriptEngine instance. It should work as long as ClearScriptV8-32.dll and v8-ia32.dll are in the same directory.

Good luck!

New Post: Retrieving javascript line index during execution

$
0
0
Hello rovs,

The following test runs to completion without script termination or infinite recursion, and the output is exactly as expected:
publicclass Test {
    public ScriptEngine Engine { get; set; }
    publicvoid Method1(int index) {
        Console.WriteLine("{0} {1}", index, Engine.GetStackTrace());
    }
    publicvoid Method2(int index) {
        Console.WriteLine("{0} {1}", index, Engine.Script.getStackTrace());
    }
}
engine.AddHostObject("test", new Test { Engine = engine });
engine.Execute(@"
    function getStackTrace() { return new Error().stack; }
    for (var i = 0; i < 1000; i++) { test.Method1(i); }
    for (var i = 0; i < 1000; i++) { test.Method2(i); }
");
Is there something you're doing differently?

Thanks!

Edited Issue: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

Commented Issue: Double quote replaced by some other "junk" character [67]

$
0
0
Hi,
I am noticing v8Engine.Execute() fails with :
_
SyntaxError: Unexpected identifier
at Script Document xx..xxx.... -> -----------------------_
exception.

I see that normally one of the Double quotes ( " ) in the javascript text is replaced with some other characters and hence the syntax error. This seems to be intermittent issue as it doesnt happen all the time and not on all the machines the application runs.

Can you please have a look? I am using version 5.3.

thanks
Pandey

Comments: We cannot reproduce the issue, and there has been no response from Pandey in a month. Marking as resolved.

Updated Wiki: Home

$
0
0

Description

ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

Features

  • Simple usage; create a script engine, add your objects and/or types, run scripts
  • Support for several script engines: Google's V8, Microsoft's JScript and VBScript
  • Exposed resources require no modification, decoration, or special coding of any kind
  • Scripts get simple access to most of the features of exposed objects and types:
    • Methods, properties, fields, events
    • (Objects) Indexers, extension methods, conversion operators, explicitly implemented interfaces
    • (Types) Constructors, nested types
  • Full support for generic types and methods, including C#-like type inference and explicit type arguments
  • Scripts can invoke methods with output parameters, optional parameters, and parameter arrays
  • Script delegates enable callbacks into script code
  • Support for exposing all the types defined in one or more assemblies in one step
  • Optional support for importing types and assemblies from script code
  • The host can invoke script functions and access script objects directly
  • Full support for script debugging

Examples

using System;
using Microsoft.ClearScript;
using Microsoft.ClearScript.V8;

// create a script engineusing (var engine = new V8ScriptEngine())
{
    // expose a host type
    engine.AddHostType("Console", typeof(Console));
    engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)");

    // expose a host object
    engine.AddHostObject("random", new Random());
    engine.Execute("Console.WriteLine(random.NextDouble())");

    // expose entire assemblies
    engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
    engine.Execute("Console.WriteLine(lib.System.DateTime.Now)");

    // create a host object from script
    engine.Execute(@"
        birthday = new lib.System.DateTime(2007, 5, 22);
        Console.WriteLine(birthday.ToLongDateString());
    ");

    // use a generic class from script
    engine.Execute(@"
        Dictionary = lib.System.Collections.Generic.Dictionary;
        dict = new Dictionary(lib.System.String, lib.System.Int32);
        dict.Add('foo', 123);
    ");

    // call a host method with an output parameter
    engine.AddHostObject("host", new HostFunctions());
    engine.Execute(@"
        intVar = host.newVar(lib.System.Int32);
        found = dict.TryGetValue('foo', intVar.out);
        Console.WriteLine('{0} {1}', found, intVar);
    ");

    // create and populate a host array
    engine.Execute(@"
        numbers = host.newArr(lib.System.Int32, 20);
        for (var i = 0; i < numbers.Length; i++) { numbers[i] = i; }
        Console.WriteLine(lib.System.String.Join(', ', numbers));
    ");

    // create a script delegate
    engine.Execute(@"
        Filter = lib.System.Func(lib.System.Int32, lib.System.Boolean);
        oddFilter = new Filter(function(value) {
            return (value & 1) ? true : false;
        });
    ");

    // use LINQ from script
    engine.Execute(@"
        oddNumbers = numbers.Where(oddFilter);
        Console.WriteLine(lib.System.String.Join(', ', oddNumbers));
    ");

    // use a dynamic host object
    engine.Execute(@"
        expando = new lib.System.Dynamic.ExpandoObject();
        expando.foo = 123;
        expando.bar = 'qux';
        delete expando.foo;
    ");

    // call a script function
    engine.Execute("function print(x) { Console.WriteLine(x); }");
    engine.Script.print(DateTime.Now.DayOfWeek);

    // examine a script object
    engine.Execute("person = { name: 'Fred', age: 5 }");
    Console.WriteLine(engine.Script.person.name);
}

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Here's the full exception:

Exception=System.TypeLoadException: Cannot load V8 interface assembly. Load failure information for v8-ia32.dll:
C:\DWASFiles\Sites\mobile$Service\Temporary ASP.NET Files\root\1aa0fcb8\40098f63\assembly\dl3\c1d3aac4\a232f205_bb52d001\v8-ia32.dll: The specified module could not be found
D:\Program Files (x86)\SiteExtensions\MobileServicesDotNet\1.0.450\v8-ia32.dll: The specified module could not be found
D:\Program Files (x86)\SiteExtensions\MobileServicesDotNet\1.0.450\bin\v8-ia32.dll: The specified module could not be found
at Microsoft.ClearScript.V8.V8Proxy.LoadNativeLibrary()
at Microsoft.ClearScript.V8.V8Proxy.LoadAssembly()
at Microsoft.ClearScript.V8.V8Proxy.GetAssembly()
at Microsoft.ClearScript.V8.V8Proxy.GetImplType(Type type)
at Microsoft.ClearScript.V8.V8Proxy.CreateImpl[T](Object[] args)
at Microsoft.ClearScript.V8.V8IsolateProxy.Create(String name, V8RuntimeConstraints constraints, Boolean enableDebugging, Int32 debugPort)
at Microsoft.ClearScript.V8.V8Runtime..ctor(String name, V8RuntimeConstraints constraints, V8RuntimeFlags flags, Int32 debugPort)
at Microsoft.ClearScript.V8.V8ScriptEngine..ctor(V8Runtime runtime, String name, V8RuntimeConstraints constraints, V8ScriptEngineFlags flags, Int32 debugPort)

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
I was able to get it working using your assembly resolve code. Thanks!

New Post: Retrieving javascript line index during execution

$
0
0
Thank you!
Turns out the culprit was in some supporting code.
Both ScriptEngine.GetStackStrace() and JS method work as expected!

New Post: Azure Mobile Services Cannot Load V8 Interface Assembly

$
0
0
Hi AEONSoft,

Glad to hear that you got it working!

If you get a chance, we'd still very much like to know what AppDomain.CurrentDomain.BaseDirectory and AppDomain.CurrentDomain.RelativeSearchPath return in your deployment scenario.

Thanks!

New Post: Call known method by name

$
0
0
Per this thread here:
https://clearscript.codeplex.com/discussions/467402

I should be able to do
ScriptEngine.Script["MyMethod"](arg1, arg2);
But I get exception:
Cannot apply indexing with [] to an expression of type 'System.Dynamic.DynamicObject'
Per this thread here:
https://clearscript.codeplex.com/discussions/537917

the extension method blows up in the same way.
var del = (Delegate)host.func<object>(args.Length, engine.Script[name]);
engine.Script[name] is not allowed.

Am i missing something basic??

New Post: Call known method by name

$
0
0
Hello!

The following test code compiles and runs as expected:
using (var engine = new V8ScriptEngine())
{
    engine.Execute("function foo(x) { return x; }");
    Console.WriteLine(engine.Script.foo(123));  // writes "123"
    Console.WriteLine(engine.Script["foo"](456));  // writes "456"
    Console.WriteLine(engine.Invoke("foo", 789));  // writes "789"var host = new HostFunctions();
    ((IScriptableObject)host).OnExposedToScriptCode(engine);
    var del = (Delegate)host.func(1, engine.Script["foo"]);
    Console.WriteLine(del.DynamicInvoke(987));  // writes "987"
}
Are you doing something differently? What framework version are you using?

Cheers!

New Post: Call known method by name

$
0
0
Thanks for the quick response. I am using .Net 4.5.1

I tried your code sample in a console app, and an asp.net app, and it worked great.

Apparently my issue is that I am using a VisualWebGui application.
engine.Execute("function foo(x) { return x; }");
Console.WriteLine(engine.Script.foo(123));  // writes "123"
'System.Dynamic.DynamicObject' does not contain a definition for 'foo'

which mirrors the issues I am having. I can open Script in the debugger and see the foo method there.
:(

Any ideas?

New Post: Call known method by name

$
0
0
Hi again,

That's very odd. It's as if your environment doesn't support C#'s dynamic keyword properly, or is missing the required runtime infrastructure.

Does Visual WebGUI use a custom C# compiler or class library?

Thanks!

New Post: Call known method by name

Viewing all 2297 articles
Browse latest View live




Latest Images