Javascript function as .Net delegate - with .Net classes

Nov 11, 2011 at 4:06 PM


I define some functions in javascript that are used as callbacks from .Net code.  Whenever these javascript functions reference .Net classes, however, a System.Security.SecurityException ("Use of Clr is not allowed") is thrown.

This can be reproduced, for example,, using the following javascript, loosely based on one of the Jint examples:.

var list = new System.Collections.Generic.List{System.Int32}();
list = list.ConvertAll{System.Double}( function (x) { return System.Math.Sqrt(x); });
if(2 != list.Count) return 1;
if(9 != list[0]) return 1;
if(2 != list[1]) return 1;

return 0;

And, calling that script with C# similar to:

using System;
using Jint;

namespace MyNamespace
namespace MyClass
public static bool RunScript(string script) { JintEngine jint = new JintEngine(); jint.DisableSecurity(); jint.AllowClr = true; try { var result = jint.Run(script); Console.WriteLine("Return status: " + result); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } return true; }

Is this a known bug, or am I doing something wrong?  Is there a workaround or alternative?

Thanks for your wonderful work on Jint.  It (nearly) works like a dream! ;-)


Nov 13, 2011 at 9:46 AM
Edited Nov 13, 2011 at 9:46 AM

Please specify the version that you use, there was a bug in propagating properties of the engine while marshaling js functions to delegates. Try using lates sources from 'dev' brunch, hope it helps.

Nov 14, 2011 at 9:22 AM



I am using the latest release, 0.9.2 from the binary download.

Okay, I shall try the current source code instead.


Many thanks,


Nov 14, 2011 at 4:46 PM

Is the file "Jint.Temp\scripts\test.js" missing from the archive?


It looks like I can build the binary dll, but I can't run the tests.

Nov 14, 2011 at 7:06 PM

Unfortunately, using the source from earlier today, and recompiling, I have precisely the same exception thrown..

A first chance exception of type 'System.Security.SecurityException' occurred in Jint.dll

'Use of Clr is not allowed'

Nov 14, 2011 at 7:14 PM

Did you use 'dev' brunch?

Nov 14, 2011 at 7:36 PM

No, sorry..  You are absolutely right: dev branch works well!


Nov 15, 2011 at 1:50 AM

You are welcome!