0.9.0 no longer works in monotouch

Feb 27, 2011 at 9:28 PM

It looks like 0.9.0 uses reflection.emit, which makes jint unusable on the iphone (via monotouch).  0.8.9 did not generate IL and worked like a champ.

Could you make this new codegen configurable at runtime?  i.e an option to turn off IL generation and use the old mechanism from 0.8.9.


- John

Mar 3, 2011 at 10:39 PM

Unfortunatelly it's not possible,

Would you provide us with some more details about this situation and why the IL code generation is under suspect?

Mar 5, 2011 at 6:52 PM

Monotouch is limited by the underlying iphone/pad/touch platform - and will likely always be limited in this way.  Apple is not likely to relax the restriction anytime soon.  It would be great to have the option to use your library in its prior form (perhaps with a runtime config option).

On the java side, rhino allows this with the "-1" optimization option:  http://www.mozilla.org/rhino/opt.html


More details on monotouch: http://monotouch.net/Documentation/Limitations#No_Dynamic_Code_Generation


Since the iPhone's kernel prevents an application from generating code dynamically Mono on the iPhone does not support any form of dynamic code generation. These include:

  • The System.Reflection.Emit is not available.
  • No support for System.Runtime.Remoting.
  • No support for creating types dynamically (no Type.GetType ("MyType`1")), although looking up existing types (Type.GetType ("System.String") for example, works just fine).
  • Reverse callbacks must be registered with the runtime at compile time.


The lack of System.Reflection.Emit means that no code that depends on runtime code generation will work. This includes things like:

  • The Dynamic Language Runtime.
  • Any languages built on top of the Dynamic Language Runtime.
  • Remoting's TransparentProxy or anything else that would cause the runtime to generate code dynamically.
Mar 5, 2011 at 8:40 PM

I see...

To say that Jint 0.8.9 didn't generate IL code isn't entirely correct, since it used a dynamic code to provide js functions as native delegates.

Do you use clr objects from javascript?

Mar 5, 2011 at 8:46 PM

I pass clr objects to the engine using SetParameter, then refer to them in javascript.

I'm using the 0.8.9 source with only one modification, removing RegexOptions.Compiled - which is also unsupported.

Mar 5, 2011 at 9:25 PM

Ok, I understand.

We will consider this issue.

Mar 5, 2011 at 9:27 PM

Excellent, thanks.  A first class javascript engine running on i* devices combined with the productivity of monotouch is a killer combination.

Mar 5, 2011 at 9:32 PM

I think having a full interpreted mode is a main difference from other scripting engines. Though performance is also critical. The solution of having an option to turn those optimizations on/off is a good compromise to my opinion. Sergey, do you think we could abstract your changes by using specific providers for each of the technologies ?

I am also concerned by medium trust compatibility. As Jint might be used on web servers, we should ensure we handle this scenario.

Mar 5, 2011 at 10:25 PM

We have a layer of abstraction already, all interoperability features are collected to Marshaller class.

I think we need to do a moderated refactoring and to implement a new Marshaller which will wrap a native types without a dynamic code, then we will be able to specify to JintEngine which marshaller to use.

When I was writing an interoperability mechanism I tried not to use anything which requires a special privileges, so I think Jint may (hope should) work in medium trust environment.

Mar 5, 2011 at 10:49 PM

Lightweight Code Generation should work fine. Are you using anything else ?

Mar 6, 2011 at 6:09 AM


Sep 7, 2011 at 1:41 PM
Edited Sep 7, 2011 at 1:50 PM

I am also very interested in Jint, because it does not use any Just In Time Compilation, which mean that it can run on iOS (iPhone, iPad) and Windows Phone 7 and possibly everywhere there is a C# compiler.

Do not lose this feature ?


Sep 7, 2011 at 3:34 PM

Also very interested in using Jint on mobile platforms! This would be great.

Sep 14, 2011 at 1:18 AM

Has anyone got a monotouch project they could share? me[at]slodge[dot]com if you do - would be lovely! 

I will try to get 0.8.9 working on my own too.

Sep 14, 2011 at 12:46 PM

I have  jint 0.8.9 source updated to compiled under MonoTouch .NET 4. So far it works great in the iOS emulator.
Porting the code to MonoTouch, consist of

  • removing the compiled directive for regular expression 
  • fixing the namespace problem with Func and Action
  • creating the right csproj project file for monotouch

After that it is working. I was expecting problem with the ANTLR assembly, so far no problem.

Jint Team,  please make sure that Jint supports iOS and Windows Phone 7

Sep 14, 2011 at 12:51 PM

Can you share your port of 0.8.9, please? Have you removed DelegateWrapper?

Sep 14, 2011 at 2:49 PM

Yes I can. Send me an email. see my web site www.frederictorres.net.
Have you removed DelegateWrapper? No. I did not have any problem with this.

Sep 14, 2011 at 6:21 PM

Thanks for all your assistance fred.

Your project ran very quickly and easily in the simulator - I think I still have some more work to do to get it running anywhere near an iphone (plus I need to renew my apple subscription - arrrrrrrrr!)

I don't think I need DelegateWrapper for the project I'm thinking of working on... I may need one CLR function wrapped, but I guess I could hard code a wrapper for that one function.

Would be very interested to hear how others get one - I'm guessing that johnpurslock actually used this in anger? Maybe even got through the app store? Would be good to know!

Sep 15, 2011 at 6:40 AM

I found out that Jint 0.8.9 works well on device as long as you comment out creation of DelegateWrapper class. In which cases this class is used and how can we replace Reflection.Emit calls with device-safe code?

cin, sebastienros, can you give us an advice in which direction we should move to replace Reflection.Emit code in 0.8.9 and 0.9.1?

Sep 15, 2011 at 7:44 AM

That's interesting nikitamk.

Any chance you can share your project files with me -me[at]slodge[dot]com - I've got a great project from fredericaltorres that allowed me to test the simulator, but a complete device ready hello world app would be really interesting. I'm guessing you have an ANTLR project as well as a JINT one? 

I've commented out the DelegateWrapper code in my source and it looks like for my app then I won't need it (I never need to call JsFunction's as delegates?)

Would also be good to know if anyone's got this past the app store (there's always that final hurdle!)

Interesting stuff!

Sep 15, 2011 at 11:52 AM

The only change from fredericaltorres's project is to exclude DelegateWrapper.cs from a project and comment out "else if (typeof(Delegate).IsAssignableFrom(pis[i])) // wrap the JsFunction to a Delegate" block in CachedMethodInvoker.cs file. There are no changes in ANTLR project.

Sep 15, 2011 at 12:49 PM

I don't quite understand... the code I've got hasn't got an ANTLR project - it's just got a prebuilt assembly which I think is full .net and not monotouch compatible?

Or maybe my monotouch is just out of date?

Sep 15, 2011 at 12:53 PM

I use prebuilt ANTLR assembly too. Actually, I built Jint on Windows/NET4.0 and referenced compiled *dll in my MonoTouch project on Mac. They are compataible.

Sep 19, 2011 at 6:11 PM
nikitamk wrote:

I use prebuilt ANTLR assembly too. Actually, I built Jint on Windows/NET4.0 and referenced compiled *dll in my MonoTouch project on Mac. They are compataible.

I don't understand how to do this...

I just can't get it to build for the device right now :(

And according to the FAQ, what you are doing should not work: http://ios.xamarin.com/FAQ#Can_I.c2.a0use_standard_desktop_Mono_assemblies_or_.NET.c2.a0assemblies_with_MonoTouch.3f

I'm really not sure how to get this to build (I've been trying to compile antlr too - but haven't yet found the old version of the source used in Jint - I will find it!)

Sep 19, 2011 at 9:22 PM

I decompiled the existing dll... and have just about got the project building - just the native compile step failing now :( More tomorrow...

Sep 20, 2011 at 3:06 PM

What is the error message from compiler? I'm using several Windows dlls in my project and all of them seems to work ok. Do you have the latest versions of Mono / MonoTouch / MonoDevelop?

Sep 30, 2011 at 5:36 PM

I am back on porting Jint to iOS. I was yesterday with some of the mono folks. So I could get some help if needed.

One advise, I received is: Did you test it on a device ?  

In my case it works ok on the emulator (once the code using reflection emit is commented). But I did not test it yet on a device.

Did anybody got Jint to run on a Device?



Oct 11, 2011 at 5:51 AM


Sorry I went quiet there... got distracted by work!

nikitamk - just doesn't work with my old (3.6) version of MT - and the docs say it still shouldn't work. I could try the latest version..... if someone lends me the money :) 

fredericaltorries - yes I ran code on my 3G without any problems - but I did *not* submit anything to app store.

I also looked at using the standard javascriptcore library from within MT using PInvoke - a test on that seemed to work OK but I only did the very bare minimal hack to get it working - would be more work to get the full PInvoke wrapper.


Dec 7, 2011 at 1:17 AM

Any update on this issue?  I'd like to know before I do my own fork (custom source rebuild).

Just to be clear: The binary release Jint.dll (i only tested 0.8.9) will only work with the MonoTouch Simulator without any source modification.

It will not work with the devices (iPhone/iPad). I tested with latest MonoTouch(5.0.3)/iOS(4.2) SDK.  You will get a link error as stated above (e.g. Reflection.Emit) when you build a device version.

I will most likely follow nikitamk solution. with the native ANTLR and patched jint assembly.

@nikitamk, are you still having success with 0.8.9 and just the removal of DelegateWrapper.cs?

Jul 21, 2012 at 5:36 PM

Are there any new info regarding using the newest version with MonoTouch?


Could anybody send me in e-mail the Antlr Runtime source code which is needed to compile 0.8.9 on MonoTouch? I think, it needs Antlr 3.2, but i was unable to find the sources, only the binaries.

Oct 19, 2013 at 12:28 PM

I am just curious if this "medium refactoring" has already been done yet, that would make it possible to disable "Reflaction.Emit" and stuff, so I can use Jint with monotouch and monodroid. :) pressing thumbs

I guess this is a very important feature for a lot of folks in the xamarin community!
Oct 19, 2013 at 5:47 PM

Sent from my iPhone