SetGlobalFunction and Silverlight

Sep 6, 2011 at 9:51 PM

I've modified the SilverlightREPL project to add the global function from the documentation (add). When attempting to execute this function, I get the following error:

Attempt by method 'DynamicClass.binder_for_SilverlightREPL.MainPage.<.ctor>b__0(Jurassic.ScriptEngine, System.Object, System.Object[])' to access method 'SilverlightREPL.MainPage.<.ctor>b__0(Int32, Int32)' failed.

Any idea why this isn't working from SL?

Sep 6, 2011 at 11:25 PM
Edited Sep 6, 2011 at 11:25 PM

Dynamically generated code can only access public methods in Silverlight, due to security restrictions (Reflection has the same restriction).  I'm guessing your method is an anonymous lambda which IIRC will be compiled into a private method.  Make a public method and pass that and it should work.

Sep 7, 2011 at 12:10 AM


Thanks again for the quick response. It looks like you are correct as once I replace the lambda w/ a public method it's working as expected.



Sep 9, 2011 at 10:12 AM

Same result here :)

Can you update the documentation page with a sl-compatible example - e.g:


            var engine = new Jurassic.ScriptEngine();
            engine.SetGlobalFunction("alert", new Func<string,bool>(PseudoAlert));
            Console.WriteLine(engine.Evaluate<bool>("alert('hello world')"));

        public bool PseudoAlert(string message)
            return true;