embedded monotouch

shawnshawn CAMember

I'm trying to embed some MonoTouch code within an Objective-C program. I've got a very simple C# test library that contains a single static class with a single static method. The method is passed two integers, adds them together and returns the result. I've also got a simple Obj-C program that contains a view controller with a button on it. Pressing the button invokes a method that initializes Mono, calls the Add method in the C# library, and then cleans up Mono. Everything works just fine in the simulator, but I'm having no luck with running it on a device. I get an exception when I call mono_jit_init(). The exception is caused by an assertion in mono_arch_create_generic_trampoline() in tramp-arm.c. I've looked at the code, and the assertion is the only line in that function. It looks like the real function has been eliminated by the following: #ifndef DISABLE_JIT.

Has anybody had any success with embedding C# in an Obj-C program? Am I doing something wrong?

P.S. I'm using the include files and linking with the libraries from /Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr.


  • JasonAwbreyJasonAwbrey USInsider, University, Developer Group Leader mod

    I'm pretty sure this just doesn't work. iOS doesn't allow JIT, only AOT.

  • JosephHillJosephHill USForum Administrator, Xamarin Team Xamurai

    Embedding C# in Objective-C applications is not supported.

    It is possible to integrate with MonoTouch and Objective-C by building your Objective-C code into a library, and binding this library with Binding Projects. More information can be found here:

    Hope that helps

  • shawnshawn CAMember

    Unfortunately, we can't do it the other way around. With the help of MonoTouch, we've spent the last year and a half successfully porting a very large and complex PC VOIP app to the iPhone. It's now in the app store and we're absolutely thrilled with how well MonoTouch has worked for us. However, we now have a large customer that wants to use a significant subset of our code within their own Objective-C app, so we would like to package that code up as a library, maybe even making it something we could sell to other customers.

    Embedding MonoTouch looks like the perfect solution to us, and I've seen numerous references on StackOverflow suggesting that others have it working, but there just aren't enough details to work from. Now, finding out that's it's not officially supported, our only solution will be to completely rewrite a large chunk of C# code in Objective-C. This leads me to the following questions:

    1) Is embedding MonoTouch a possible solution even though it isn't "officially" supported?

    2) If so, is it something that could go away or easily break in the future, or is it something that will become officially supported?

    3) Is there any other approach we can take where we can make use of our existing C# code?

  • diablohshdiablohsh CNMember

    @JosephHill is embedding C# in C++(ios) applications supported?

Sign In or Register to comment.