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 7963909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:44:14+00:00 2026-06-04T05:44:14+00:00

I’m trying to call Unity C# script from the Objective-C side. Functions with void

  • 0

I’m trying to call Unity C# script from the Objective-C side. Functions with void parameters work. Functions with string parameters work if the script on the other side is Javascript.

Functions with string parameters crash if the script on the other side is C#. The crash is a BAD_EXEC.

I’m fairly sure I’m not correctly marshalling parameters correctly. There really isn’t too much documentation about this on the web.

I’ve read Embedding Mono and I’ve looked at the really old examples on Github.

http://www.mono-project.com/Embedding_Mono
https://github.com/mono/mono/tree/master/samples/embed

Types and functions are declared as such:

typedef void* MonoDomain;
typedef void* MonoAssembly;
typedef void* MonoImage;
typedef void* MonoClass;
typedef void* MonoObject;
typedef void* MonoMethodDesc;
typedef void* MonoMethod;
typedef void* MonoString;
typedef int   gboolean;

MonoDomain*     mono_domain_get();
MonoAssembly*   mono_domain_assembly_open(MonoDomain* domain, const char *assemblyName);
MonoImage*      mono_assembly_get_image(MonoAssembly* assembly);
MonoMethodDesc* mono_method_desc_new(const char* methodString, gboolean useNamespace);
MonoMethodDesc* mono_method_desc_free(MonoMethodDesc* desc);
MonoMethod*     mono_method_desc_search_in_image(MonoMethodDesc* methodDesc, MonoImage* image);
MonoObject*     mono_runtime_invoke(MonoMethod* method, void* obj, void** params, MonoObject** exc);
MonoClass*      mono_class_from_name (MonoImage *image, const char* name_space, const char *name);
MonoString*     mono_string_new(MonoDomain* domain, const char* str);

Then variables are declared:

@interface UnityObject : NSObject
{
    MonoDomain*     domain;
    NSString*       assemblyPath;
    MonoAssembly*   monoAssembly;
    MonoImage*      monoImage;
    MonoMethodDesc* runChallengeDesc;
    MonoMethod*     runChallengeMethod;
}
@end

And then in init:

- (id)init
{
    if ((self = [super init]))
    {
        assemblyPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Data/Managed/Assembly-CSharp-firstpass.dll"];
        domain = mono_domain_get();
        monoAssembly = mono_domain_assembly_open(domain, assemblyPath.UTF8String);
        monoImage = mono_assembly_get_image(monoAssembly);
        runChallengeDesc = mono_method_desc_new("Marshal:RunChallenge(string)", FALSE);
        runChallengeMethod = mono_method_desc_search_in_image(runChallengeDesc, monoImage);
        mono_method_desc_free(runChallengeDesc);
    }

    return self;
}

The above all works as expected.

Then the method is called:

NSString *msg = @"Some message string";
MonoString *str = mono_string_new(domain, msg.UTF8String);
void *args[1];
args[0] = &str;
if (runChallengeMethod)
    mono_runtime_invoke(runChallengeMethod, NULL, args, NULL);

I’m fairly sure I’m not correctly marshalling parameters correctly. The crash is a BAD_EXEC.

  • 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-06-04T05:44:16+00:00Added an answer on June 4, 2026 at 5:44 am

    I’d advise you to elaborate a little more on the code you posted. With the code you posted, assuming that the “…” is implemented correctly, you are executing a static method with 1 parameter that is undefined.

    You at least need to do this instead:

    void* args[1];
    
    args[0] = mono_string_new(domain, msg.UTF8String);
    
    mono_runtime_invoke (method, NULL, args, NULL);
    

    I can only guess that the transcription from your real code to this question was done poorly as almost 0 of the code you posted is valid.

    The code at http://www.mono-project.com/Embedding_Mono#Creating_objects shows how to pass Mono Strings when they are not out or by ref.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.