Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3985978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:57:23+00:00 2026-05-20T05:57:23+00:00

I’ve embedded some C# code into an iphone objective-c app using monotouch. I’m able

  • 0

I’ve embedded some C# code into an iphone objective-c app using monotouch. I’m able to call into the C# code and get a return value, but I am not able to invoke a C function from the C# code using PInvoke. I am attempting to get a trivial example working. It is a simple calculator. The objective c code calls into the C# code to add two integers. The C# code should then call back into the objective-c code and give it the updated value. Below is the C# code that handles the calculation:

public class MyClass
{       
    static public void Add(int a, int b)
    {
        updateResult(a + b);
    }

    [DllImport("__Internal", EntryPoint="updateResult")]
    static extern public void updateResult(int result);
}

Here is my code that initializes mono and handles the add method:

@implementation Mono

- (id)init {
self = [super init];

if (self) {
    NSBundle *main = [NSBundle mainBundle];
    NSString *path = [main bundlePath];
    const char *c_path = [path UTF8String];

    [main autorelease];
    [path autorelease];

    chdir (c_path);
    setenv ("MONO_PATH", c_path, 1);
    setenv ("MONO_XMLSERIALIZER_THS", "no", 1);
    setenv ("DYLD_BIND_AT_LAUNCH", "1", 1);
    setenv ("MONO_REFLECTION_SERIALIZER", "yes", 1);

#if defined (__arm__)
    mono_aot_register_module (mono_aot_module_mscorlib_info);
    mono_aot_register_module (mono_aot_module_Math_info);

    mono_jit_set_aot_only (TRUE);
#endif
    mono_jit_init("MonoTouch");
    MonoAssembly *assembly = mono_assembly_open("Math.dll", NULL);
    MonoImage *img = mono_assembly_get_image(assembly);
    MonoClass *cls = mono_class_from_name(img, "Math", "MyClass");
    MonoMethodDesc *methodDesc = mono_method_desc_new("Math.MyClass:Add", TRUE);
    _addMethod = mono_method_desc_search_in_class(methodDesc, cls);
}

return self;
} 

- (void)addA:(int)a plusB:(int)b {
    void *params[] = { &a, &b };
    mono_runtime_invoke(_addMethod, NULL, params, NULL);
}

@end

and here is the definition of the updateResults method:

extern void updateResult(int result) {
    printf("Got Result");
}

When the updateResults is called from the C# side of things I get the following exception:

Unhandled Exception: System.EntryPointNotFoundException: updateResult
at (wrapper managed-to-native) Math.MyClass:updateResult (int)
at Math.MyClass.Add (Int32 a, Int32 b) [0x00000] in <filename unknown>:0 

I can see the symbol in the binary with the following command:

$ nm Calc | grep updateResult
00002b2e t _updateResult

Setting the MONO_LOG_LEVEL environment variable to debug I get the following output when attempting the PInvoke. It looks like it finds the method and then can’t find it:

Mono: DllImport attempting to load: ‘_Internal’.Mono: Searching for ‘updateResult’.Mono: Probing ‘updateResult’.Mono: Probing ‘updateResult’.Mono: Probing ‘updateResultA’.Mono: Probing ‘updateResultA’.Mono: DllImport attempting to load: ‘_Internal’.Mono: Searching for ‘updateResult’.Mono: Probing ‘updateResult’.Mono: Probing ‘updateResult’.Mono: Probing ‘updateResultA’.Mono: Probing ‘updateResultA’.Mono: AOT FOUND AOT compiled code for (wrapper managed-to-native) Math.MyClass:updateResult (int) 0x3bc8 – 0x3d90 0x3dcb

Mono: DllImport attempting to load: ‘__Internal’.Mono: Searching for ‘updateResult’.Mono: Probing ‘updateResult’.Mono: Probing ‘updateResult’.Mono: Probing ‘updateResultA’.Mono: Probing ‘updateResultA’.Unable to resolve pinvoke method ‘Math.MyClass:updateResult (int)’ Re-run with MONO_LOG_LEVEL=debug for more information.

I’ve spent quite some time trying to figure this out. From what I’ve read it seems like this should be pretty trivial, but I can’t get it to work. Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:57:24+00:00Added an answer on May 20, 2026 at 5:57 am

    Would it be better to use Selectors?

    That is the default path to follow as suggested by the makers of MonoTouch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
We're building an app, our first using Rails 3, and we're having to build
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.