Problem using .NET classes from scripts

Aug 30, 2011 at 1:57 AM

I am having a problem accessing some of my .NET classes from scripts.    I can access some classes fine, e.g., in the System namespace, and even classes in the Jint namespace, but classes in other namespaces that I define are not recognized.  I get the following JintException:

    Right argument should be a function: Jint.Expressions.MemberExpression

I have set AllowClr to true and called DisableSecurity().   Any other issues that could block access to certain classes?

Btw, I have the same problem in both .NET and Mono.

Thanks, -CR


Aug 30, 2011 at 1:59 AM

Can you give a nexample ? One that I can reproduce ?

By the way... I could not find a way to get lexer errors, even with your article, which is not adapted to the C# version of antlr.

Aug 30, 2011 at 2:20 AM

Well, the fully story is a bit more complicated (of course :-).   The classes that I want to access from scripts are in a .NET library produced by IKVM.   I know my whole system is basically working because the IKVM-generated code creates the instance of Jint and calls Run and the whole system runs fine.  The problem occurs when, inside a script, I am trying to "call back" to some of my .NET classes (hard to explain why).  Then I get the error above.  I will try to make a very small example, but it is not easy.

That's why I am kind of asking for a general list of reasons (other than security), which would prevent something like MyName.MyClass being recognized as a class name (like System.Console).   Is the specific JintException above any clue?

I tried poring over the source code some more to look for clues, but it is a bit daunting.

Thanks, -CR

Aug 30, 2011 at 4:44 AM

You might need to load the assembly first. Before calling Jint, try do instanciate one of those classes outside of Jint, to force the CLR to load it.

Aug 30, 2011 at 12:57 PM

Good suggestion, but I am quite sure that the class is loaded, since one test I tried is the script:

       "new Object() instanceof MyName.MyClass"

where MyName.MyClass is the main class that creates the JintEngine and calls it :-).

Any other things that could go wrong?



Aug 31, 2011 at 7:36 AM

It looks like the class isn't loaded, try to test is "MyName.MyClass" defined.